/* @(#)GSBalanceProcessor.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-4-20   新增
 *   Jenny Li    2006-6-5    新增需求：作废删除或订单作废向交易平台发送信息，故
 *                           修改方法abolishBalanceInfo,abolishUnBalance
 *                           添加方法submitAbolishDetailToApep
 *   Jenny Li    2006-6-7    添加方法addSignedOrderDetailToBalMsg，processProviderBalMsg
 *                           getProviderBalanceYM，getBalDatePeriod  
 *   Jenny Li    2006-6-22   修改方法productRecvInfo中查询合同费用传入的参数                                             
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.business;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;

import com.hitrust.gs.bean.GSBalanceMsgBean;
import com.hitrust.gs.bean.GSBalanceParamBean;
import com.hitrust.gs.bean.GSBargainChargeBean;
import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSOrganizationBean;
import com.hitrust.gs.bean.GSPayReceiveAbleBean;
import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.bean.GSStocksOtherBean;
import com.hitrust.gs.dao.GSBalanceFeeDAO;
import com.hitrust.gs.dao.GSBalanceMsgDAO;
import com.hitrust.gs.dao.GSBalanceParamDAO;
import com.hitrust.gs.dao.GSBargainDAO;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.dao.GSOperatorDAO;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.dao.GSOrganizationDAO;
import com.hitrust.gs.dao.GSPayReceiveAbleDAO;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.dao.GsStocksDao;
import com.hitrust.gs.form.GSAddUnBalanceDetailForm;
import com.hitrust.gs.form.GSBalanceInfoRecordeForm;
import com.hitrust.gs.form.GSBalanceAuditConfirmForm;
import com.hitrust.gs.integration.socket.GSClientSocket;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.GenRandNum;
import com.hitrust.gs.util.ParameterFactory;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.vo.GSBalanceInfoVO;
import com.hitrust.gs.vo.GSBalanceManagePayReceiveVO;
import com.hitrust.gs.vo.GSBalanceManagePayRecvSaveVO;
import com.hitrust.gs.vo.GSBalanceManageQueryResultVO;
import com.hitrust.gs.vo.GSBalanceManageQueryVO;
import com.hitrust.gs.vo.GSBalancedDetailProvResultVO;
import com.hitrust.gs.vo.GSBalancedDetailQryResultVO;
import com.hitrust.gs.vo.GSBargainAndChargeVO;
import com.hitrust.gs.vo.GSUnBalanceDetailOptVO;
import com.hitrust.gs.vo.GSUnBalanceDetailQryVO;

/**
 * 
 */
public class GSBalanceProcessor {
    /**
     * 2008-9-11 修改结算模式，以订单结算只产生应付（供应商数据） 应收根据领用明细产生
     * 
     * @author peng.ning
     */
    private boolean doBalanceRecord(String indexs[], String tEndDate1, GSOperatorBean tOperBean, String date[]) throws GSException {
        boolean tFlag = false;
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        GSManufactureDAO tMDAO = new GSManufactureDAO();
        String CCZXID = GSSystemConfigurator.getParam("gs.provider.cczxid");
        Connection tConn = null;

        // 是否已结算
        boolean purIsBalance = false; // 采购单位
        boolean proIsBalance = false; // 采购单位

        try {
            tConn = tOrderDtlDAO.getConnetion();
            tConn.setAutoCommit(false);

            GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
            HashMap tInsProvMap = new HashMap();// 新增供应商
            HashMap tUpdProvMap = new HashMap();// 修改供应商
            // 3:分别对每个被选订单明细作供应商结算
            for (int i = 0; i < indexs.length; i++) {
                GSOrderDetailBean tDetailBean = tOrderDtlDAO.queryOrderDetailByDetailId(tConn, indexs[i]);
                // 修改该笔订单明细为已纳入结算
                tDetailBean.setGs_is_balanced(GSBaseConstants.BALANCE_STATUS);
                tDetailBean.setGs_balance_month(tEndDate1);
                // tOrderDetailBean.setGs_balance_month_provider(tProviderBalYM);
                tDetailBean.setGs_lastmodifer_id(tOperBean.getGs_oper_id());
                tDetailBean.setGs_lastmodify_contents("订单明细纳入订货单位结算");
                tDetailBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss"));
                // 修改订单明细的订货单位结算状态
                tFlag = tOrderDtlDAO.updateDetailBalanced(tConn, tDetailBean);
                if (!tFlag) {
                    GSLogWriter.error(this, "修改订单明细为已订货单位结算状态失败");
                    throw new GSException(GSException.E40006, GSException.E40006_MSG);
                }
                // 3.2:如果该订单明细已经做过供应商结算，则不再进行供应商结算
                if (GSBaseConstants.UNBALANCE_STATUS.equals(tDetailBean.getGs_is_prov_balanced())) {
                    // 如果该订单明细所属的供应商已经进行了本月结算则不再做本月结算
                    GSManufactureBean tMBean = tMDAO.getManufacture(tDetailBean.getGs_manufacture_id());
                    String curProviderId = "0".equals(tMBean.getGs_is_tradeflat_manufacture()) ? CCZXID : tDetailBean.getGs_provider_id();
                    ArrayList tTempList2 = tBalMsgDAO.getBalanceMsg(curProviderId, tEndDate1);
                    if (tTempList2.size() > 0 && ((GSBalanceMsgBean) tTempList2.get(0)).getGs_balance_sign().equals(GSBaseConstants.BALANCE_STATUS)) {
                        proIsBalance = true;
                        GSProviderDAO pd = new GSProviderDAO();
                        GSProviderBean pb = pd.queryProvider(curProviderId);
                        if (pb == null)
                            pb = new GSProviderBean();
                        GSLogWriter.error(this, "供应商" + curProviderId + (pb.getGs_provider_shortname()) + "已经完成" + tEndDate1 + "结算，无法将本订单明细纳入当月结算");
                        throw new GSException("供应商[" + pb.getGs_provider_shortname() + "]已经完成" + tEndDate1 + "结算，无法将本订单明细纳入当月结算。");
                    } else {// 对该订单明细执行纳入当月结算
                        // 累加产品金额
                        BigDecimal temp = new BigDecimal(tDetailBean.getGs_goods_unitprice()).multiply(new BigDecimal(tDetailBean.getGs_signin_count()));
                        if (tTempList2.size() == 0) {// 需要新增一条供应商纳入结算记录
                            if (tInsProvMap.containsKey(curProviderId)) {
                                BigDecimal tempBD = (BigDecimal) tInsProvMap.get(curProviderId);
                                tempBD = tempBD.add(temp);
                                tInsProvMap.put(curProviderId, tempBD);
                            } else {
                                tInsProvMap.put(curProviderId, temp);
                            }
                        } else {// 需要修改现有的供应商纳入结算记录
                            if (tUpdProvMap.containsKey(curProviderId)) {
                                BigDecimal tempBD = (BigDecimal) tUpdProvMap.get(curProviderId);
                                tempBD = tempBD.add(temp);
                                tUpdProvMap.put(curProviderId, tempBD);
                            } else {
                                tUpdProvMap.put(curProviderId, temp);
                            }
                        }
                        // 修改该笔订单明细为已纳入结算
                        tDetailBean.setGs_is_prov_balanced(GSBaseConstants.BALANCE_STATUS);
                        tDetailBean.setGs_balance_month_provider(tEndDate1);
                        tDetailBean.setGs_lastmodifer_id(tOperBean.getGs_oper_id());
                        tDetailBean.setGs_lastmodify_contents("订单明细纳入供应商结算");
                        tDetailBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss"));
                        // 修改订单明细的供应商结算状态
                        tFlag = tOrderDtlDAO.updateDetailBalancedProv(tConn, tDetailBean);
                        if (!tFlag) {
                            GSLogWriter.error(this, "修改订单明细为已供应商结算状态失败");
                            throw new GSException(GSException.E40006, GSException.E40006_MSG);
                        }
                    }
                }
            }

            GSBalanceInfoVO tVO = new GSBalanceInfoVO();
            // 5:为供应商进行结算录入
            // 5.1:需要新增供应商结算记录的
            Iterator it1 = tInsProvMap.keySet().iterator();
            while (it1.hasNext()) {
                String providerId = it1.next().toString();
                BigDecimal provAmt = (BigDecimal) tInsProvMap.get(providerId);

                tVO = new GSBalanceInfoVO();
                tVO.deptId = providerId;
                tVO.balanceYM = tEndDate1;
                tVO.startDate = DateUtil.formatDate(date[0]);// aForm.getBalanceStrDate()
                tVO.endDate = DateUtil.formatDate(date[1]);// aForm.getBalanceEndDate()
                tVO.totalAmt = provAmt.doubleValue();
                tVO.payType = GSBaseConstants.PAYMENT_TYPE;
                tVO.balanceFlag = GSBaseConstants.UNBALANCE_STATUS;
                tVO.operatorId = tOperBean.getGs_oper_id();
                tVO.operateDate = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                tVO.deptType = GSBaseConstants.BALANCE_PROVIDER_TYPE;
                tFlag = tBalMsgDAO.insertBalanceInfo(tVO, tConn);
                if (!tFlag) {
                    GSLogWriter.error(this, "写结算信息表失败");
                    throw new GSException(GSException.E40006, GSException.E40006_MSG);
                }
            }
            // 5.2:需要修改供应商结算记录的
            Iterator it2 = tUpdProvMap.keySet().iterator();
            while (it2.hasNext()) {
                String providerId = it2.next().toString();
                BigDecimal provAmt = (BigDecimal) tUpdProvMap.get(providerId);

                String[] tBalMsg = new String[] { providerId, provAmt.toString() };
                tFlag = tBalMsgDAO.updateBalanceSum(tConn, tBalMsg, tEndDate1, tOperBean.getGs_oper_id());
                if (!tFlag) {
                    GSLogWriter.error(this, "修改结算信息表中已存在供应商结算金额失败");
                    throw new GSException(GSException.E40006, GSException.E40006_MSG);
                }
            }

            // 采购单位没纳入结算
            if (purIsBalance == false && proIsBalance == false) {
                // 6:检查是否有效的结算过程
                if (tInsProvMap.isEmpty() && tUpdProvMap.isEmpty()) {
                    GSLogWriter.error(this, "无可写入到结算信息表的数据，需检查数据或程序");
                    throw new GSException(GSException.E40002, GSException.E40002_MSG);
                } else {
                    if (tFlag) {
                        tConn.commit();
                        GSLogWriter.info(this, "成功新增或修改结算信息表中供应商的结算金额");
                    }
                }
            }

        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        } finally {
            try {
                if (tConn != null) {
                    tConn.setAutoCommit(true);
                }
                GSBaseDAO.close(tConn);
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return tFlag;

    }

    /**
     * 进行结算录入，对当前结算月的所有订单明细进行检测
     * 分别对订货单位和供应商进行结算，根据gs_is_balanceed字段和gs_is_prov_balanceed字段标记是否已经经过结算
     * 
     * @param aForm
     * @return
     * @throws GSException
     */
    public boolean balanceInfoRecordSelected(GSBalanceAuditConfirmForm aForm) throws GSException {

        // 0:取得当前操作员信息
        GSOperatorBean tOperBean = (GSOperatorBean) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        String tEndDate = aForm.getBalanceEndDate();
        tEndDate = tEndDate.substring(0, 4) + tEndDate.substring(5, 7) + tEndDate.substring(8, 10);
        // 1:计算当前结算月
        String tEndDate1 = tEndDate.substring(0, 6);
        // 2:取得当前所有被选订单明细信息
        String[] indexs = aForm.getIndexs();

        boolean tFlag = false;
        tFlag = doBalanceRecord(indexs, tEndDate1, tOperBean, new String[] { aForm.getBalanceStrDate(), aForm.getBalanceEndDate() });

        return tFlag;

    }

    /**
     * 进行结算录入，对当前结算月的所有订单明细进行检测
     * 分别对订货单位和供应商进行结算，根据gs_is_balanceed字段和gs_is_prov_balanceed字段标记是否已经经过结算
     * 
     * @param aForm
     * @return
     * @throws GSException
     * 
     * 修改：生成订货单位信息（应收信息）从领用表生成，生成供应商信息（应付信息）从领用表和订单表生成
     */
    public boolean balanceInfoRecordSimple(GSBalanceInfoRecordeForm aForm) throws GSException {
        boolean tFlag = false;
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        GsStocksDao stocksdao = new GsStocksDao();
        try {
            // 0:取得当前操作员信息
            GSOperatorBean tOperBean = (GSOperatorBean) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            String tEndDate = aForm.getBalanceEndDate();
            tEndDate = tEndDate.substring(0, 4) + tEndDate.substring(5, 7) + tEndDate.substring(8, 10);
            // 计算当前结算月
            String tEndDate1 = tEndDate.substring(0, 6);
            GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
            // 1.1:判断该月份此订货单位是否存在结算信息
            // 1.2如果已经存在结算信息，则不能重新结算
            if (aForm.getPayType().equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)) {
                ArrayList tList2 = tBalMsgDAO.queryBalanceInfo(aForm.getOrderDeptId(), tEndDate1);
                if (tList2.size() > 0) {
                    GSLogWriter.error(this, GSException.E40001_MSG);
                    throw new GSException(GSException.E40001, GSException.E40001_MSG);
                }
            }
            if (aForm.getPayType().equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)) {
                ArrayList tList2 = tBalMsgDAO.queryBalanceInfo(aForm.getProvider(), tEndDate1);
                if (tList2.size() > 0) {
                    GSLogWriter.error(this, GSException.E40053_MSG);
                    throw new GSException(GSException.E40053, GSException.E40053_MSG);
                }
            }
            // 查询所有可生成结算明细的领用信息（应收只在领用表中产生）
            if (aForm.getPayType().equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)) {
                String[] tStr = { DateUtil.formatDate(aForm.getBalanceEndDate()), "org", aForm.getOrderDeptId() };
                ArrayList tList = stocksdao.getStocksDetailBalanceResult3(tStr);
                if (tList != null && tList.size() > 0) {
                    String[] indexs = new String[tList.size()];
                    for (int i = 0; i < tList.size(); i++) {
                        GSStocksOtherBean sobean = (GSStocksOtherBean) tList.get(i);
                        indexs[i] = sobean.getGs_detail_id();
                    }
                    String[] date = { DateUtil.formatDate(aForm.getBalanceStrDate()), DateUtil.formatDate(aForm.getBalanceEndDate()) };
                    // 进行结算
                    tFlag = stocksdao.doBalanceRecord(indexs, tEndDate1, tOperBean, date);
                } else {
                    throw new GSException("该运营公司领用明细不存在");
                }
            }
            // 查询所有可生成结算明细的领用信息及订单明细（应付在领用及订单表中产生）
            if (aForm.getPayType().equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)) {
                String[] tStr = { DateUtil.formatDate(aForm.getBalanceEndDate()), "prov", aForm.getProvider() };
                ArrayList tList = stocksdao.getStocksDetailBalanceResult3(tStr);
                String[] indexs = null;
                String[] date = { DateUtil.formatDate(aForm.getBalanceStrDate()), DateUtil.formatDate(aForm.getBalanceEndDate()) };
                if (tList != null && tList.size() > 0) {
                    indexs = new String[tList.size()];
                    for (int i = 0; i < tList.size(); i++) {
                        GSStocksOtherBean sobean = (GSStocksOtherBean) tList.get(i);
                        indexs[i] = sobean.getGs_detail_id();
                    }
                    // 进行领用明细结算
                    tFlag = stocksdao.doBalanceRecord(indexs, tEndDate1, tOperBean, date);
                }
                // 进行订单明细结算
                ArrayList tList2 = tOrderDtlDAO.queryUnBalanceDetailProv(aForm.getProvider(), DateUtil.revertDateTime(aForm.getBalanceEndDate()));
                if (tList2 != null & tList2.size() > 0) {
                    indexs = new String[tList2.size()];
                    for (int i = 0; i < tList2.size(); i++) {
                        GSOrderDetailBean odbean = (GSOrderDetailBean) tList2.get(i);
                        indexs[i] = odbean.getGs_order_detail_id();
                    }
                    tFlag = this.doBalanceRecord(indexs, tEndDate1, tOperBean, date);
                }
                if (tList != null && tList.size() <= 0 && tList2 != null & tList2.size() <= 0) {
                    throw new GSException("该供应商领用及订单明细不存在");
                }
            }
        } catch (Exception e) {
            GSLogWriter.error(e.getMessage());
            throw new GSException(e.getMessage());
        }

        return tFlag;

    }

    /**
     * 结算信息录入
     * 
     * @param aForm
     * @return
     * @throws GSException
     */
    public boolean balanceInfoRecord(GSBalanceInfoRecordeForm aForm) throws GSException {
        boolean tFlag = false;
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        Connection tConn = null;
        try {
            tConn = tOrderDtlDAO.getConnetion();
            tConn.setAutoCommit(false);
            // 取得当前操作员信息
            GSOperatorBean tOperBean = (GSOperatorBean) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            String tEndDate = aForm.getBalanceEndDate();
            tEndDate = tEndDate.substring(0, 4) + tEndDate.substring(5, 7) + tEndDate.substring(8, 10);
            String tEndDate1 = tEndDate.substring(0, 6);

            GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
            // 判断该月份此订货单位是否存在结算信息
            ArrayList tList2 = tBalMsgDAO.queryBalanceInfo(aForm.getOrderDeptId(), tEndDate1);
            if (tList2.size() > 0) {
                GSLogWriter.error(this, GSException.E40001_MSG);
                throw new GSException(GSException.E40001, GSException.E40001_MSG);
            }
            // 查询未结算订单信息
            ArrayList tList = tOrderDtlDAO.queryUnBalanceDetail(aForm.getOrderDeptId(), tEndDate);
            ArrayList tBalanceList = new ArrayList();// 执行新增操作
            ArrayList tUpdateBalList = new ArrayList();// 执行修改操作
            if (tList.size() > 0) {
                double orderDeptTotalAmt = 0;
                double providerTotalAmt = 0;
                String tProviderId = "";
                String tProviderBalYM = "";
                String tempBalYM = "";
                GSBalanceInfoVO tBalInfoVO = null;
                for (int i = 0; i < tList.size(); i++) {
                    GSOrderDetailBean tOrderDtlBean = (GSOrderDetailBean) tList.get(i);
                    // 统计订货单位的订单明细总金额
                    orderDeptTotalAmt = orderDeptTotalAmt + tOrderDtlBean.getGs_signin_count() * tOrderDtlBean.getGs_goods_unitprice();
                    if (tProviderId.equals(tOrderDtlBean.getGs_provider_id())) {
                        providerTotalAmt = providerTotalAmt + tOrderDtlBean.getGs_signin_count() * tOrderDtlBean.getGs_goods_unitprice();
                    } else {
                        tempBalYM = "";
                        // 分别针对不同供应商统计结算金额，并放入待插入结算表的集合中
                        if (!tProviderId.equals("")) {
                            // 查询该供应商在该月份是否有已结算的信息
                            ArrayList temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tEndDate1, GSBaseConstants.BALANCE_STATUS);
                            // 供应商已经有结算信息且状态为已结算
                            if (temp2.size() > 0) {
                                // 该供应商在该月份已存在结算信息且状态为已结算，则将该笔数据纳入系统日期的下一个月份结算
                                // 计算下一个结算月份的尾时间
                                String curMonth = DateUtil.getCurrentDate("yyyyMM");
                                int tNewMonth = Integer.parseInt(curMonth.substring(4, 6)) + 1;
                                if (tNewMonth < 10) {
                                    tProviderBalYM = curMonth.substring(0, 4) + "0" + tNewMonth;
                                } else {
                                    if (tNewMonth == 13) {// 跨年
                                        tProviderBalYM = "" + (Integer.parseInt(curMonth.substring(0, 4)) + 1) + "01";
                                    } else {
                                        tProviderBalYM = curMonth.substring(0, 4) + tNewMonth;
                                    }
                                }
                                // 查询已经纳入到下一个月份结算的未结算的供应商待结算信息
                                temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tProviderBalYM, GSBaseConstants.UNBALANCE_STATUS);
                                // 把本条订单明细的金额加入到 已经纳入到下一个月份结算的未结算的供应商待结算金额中
                                if (temp2.size() == 1) {// 下一个月份结算的未结算的供应商待结算信息已经存在，合并金额
                                    GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp2.get(0);
                                    providerTotalAmt = providerTotalAmt + tBalMsgBean.getGs_balance_sum();
                                    String[] tStr = new String[2];
                                    tStr[0] = tBalMsgBean.getGs_workcorp_id();
                                    tStr[1] = String.valueOf(providerTotalAmt);
                                    tUpdateBalList.add(tStr);
                                } else {// 下一个月份结算的未结算的供应商待结算信息还未存在，新增一个项
                                    tBalInfoVO.totalAmt = providerTotalAmt;
                                    tBalInfoVO.balanceYM = tProviderBalYM;
                                    tBalInfoVO.actualBalanceDept = tBalInfoVO.deptId;
                                    tBalanceList.add(tBalInfoVO);
                                }
                            } else {
                                // 如果结算表中已存在该供应商在该月份的待结算金额，则累加
                                ArrayList temp = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tEndDate1, GSBaseConstants.UNBALANCE_STATUS);
                                if (temp.size() > 0) {// 结算表中已存在当前供应商结算数据，但尚未结算
                                    GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp.get(0);
                                    providerTotalAmt = providerTotalAmt + tBalMsgBean.getGs_balance_sum();
                                    String[] tStr = new String[2];
                                    tStr[0] = tBalMsgBean.getGs_workcorp_id();
                                    tStr[1] = String.valueOf(providerTotalAmt);
                                    tUpdateBalList.add(tStr);
                                } else {// 结算表中没有当前供应商结算数据
                                    tBalInfoVO.totalAmt = providerTotalAmt;
                                    tBalInfoVO.balanceYM = tProviderBalYM;
                                    tBalInfoVO.actualBalanceDept = tBalInfoVO.deptId;
                                    tBalanceList.add(tBalInfoVO);
                                }
                            }
                        }
                        tProviderBalYM = tEndDate1;
                        tBalInfoVO = new GSBalanceInfoVO();
                        tBalInfoVO.deptId = tOrderDtlBean.getGs_provider_id();
                        tBalInfoVO.deptType = GSBaseConstants.BALANCE_PROVIDER_TYPE;
                        tBalInfoVO.payType = GSBaseConstants.PAYMENT_TYPE;
                        providerTotalAmt = tOrderDtlBean.getGs_signin_count() * tOrderDtlBean.getGs_goods_unitprice();
                        tProviderId = tOrderDtlBean.getGs_provider_id();
                    }
                    if (tempBalYM.equals("")) {// 判断临时供应商结算月份值是否为空，若为空，则需赋值
                        tempBalYM = getProviderBalanceYM(tProviderId, tEndDate1);
                        tProviderBalYM = tempBalYM;
                    }

                    // 处理最后一笔客户统计数据的情况
                    if (i == tList.size() - 1) {
                        // 查询该供应商在该月份是否有已结算的信息
                        ArrayList temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tEndDate1, GSBaseConstants.BALANCE_STATUS);
                        if (temp2.size() > 0) {
                            // 该供应商在该月份已存在结算信息且状态为已结算，则将该笔数据纳入系统日期的下一个月份结算
                            String curMonth = DateUtil.getCurrentDate("yyyyMM");
                            int tNewMonth = Integer.parseInt(curMonth.substring(4, 6)) + 1;
                            if (tNewMonth < 10) {
                                tProviderBalYM = curMonth.substring(0, 4) + "0" + tNewMonth;
                            } else {
                                tProviderBalYM = curMonth.substring(0, 4) + tNewMonth;
                            }
                            temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tProviderBalYM, GSBaseConstants.UNBALANCE_STATUS);
                            if (temp2.size() == 1) {
                                GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp2.get(0);
                                providerTotalAmt = providerTotalAmt + tBalMsgBean.getGs_balance_sum();
                                String[] tStr = new String[2];
                                tStr[0] = tBalMsgBean.getGs_workcorp_id();
                                tStr[1] = String.valueOf(providerTotalAmt);
                                tUpdateBalList.add(tStr);
                            } else {
                                tBalInfoVO.totalAmt = providerTotalAmt;
                                tBalInfoVO.balanceYM = tProviderBalYM;
                                tBalInfoVO.actualBalanceDept = tBalInfoVO.deptId;
                                tBalanceList.add(tBalInfoVO);
                            }
                        } else {
                            // 如果结算表中已存在该供应商在该月份的待结算金额，则累加
                            ArrayList temp = tBalMsgDAO.queryBalanceInfoByOrderDept(tProviderId, tEndDate1, GSBaseConstants.UNBALANCE_STATUS);
                            if (temp.size() > 0) {
                                GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp.get(0);
                                providerTotalAmt = providerTotalAmt + tBalMsgBean.getGs_balance_sum();
                                String[] tStr = new String[2];
                                tStr[0] = tBalMsgBean.getGs_workcorp_id();
                                tStr[1] = String.valueOf(providerTotalAmt);
                                tUpdateBalList.add(tStr);
                            } else {
                                tBalInfoVO.totalAmt = providerTotalAmt;
                                tBalInfoVO.balanceYM = tProviderBalYM;
                                tBalInfoVO.actualBalanceDept = tBalInfoVO.deptId;
                                tBalanceList.add(tBalInfoVO);
                            }
                        }
                    }
                    // 修改该笔订单明细为已纳入结算
                    tOrderDtlBean.setGs_is_balanced(GSBaseConstants.BALANCE_STATUS);
                    tOrderDtlBean.setGs_balance_month(tEndDate1);
                    tOrderDtlBean.setGs_balance_month_provider(tProviderBalYM);
                    tOrderDtlBean.setGs_lastmodifer_id(tOperBean.getGs_oper_id());
                    tOrderDtlBean.setGs_lastmodify_contents("订单明细纳入结算");
                    tOrderDtlBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss"));
                    tFlag = tOrderDtlDAO.updateDetailBalanced(tConn, tOrderDtlBean);
                    if (!tFlag) {
                        GSLogWriter.error(this, "修改订单明细为已结算状态失败");
                        throw new GSException(GSException.E40006, GSException.E40006_MSG);
                    }
                }
                // 订货单位的统计结算信息放入待插入结算表的集合中
                tBalInfoVO = new GSBalanceInfoVO();
                tBalInfoVO.deptId = aForm.getOrderDeptId();
                tBalInfoVO.totalAmt = orderDeptTotalAmt;
                tBalInfoVO.balanceYM = tEndDate1;
                tBalInfoVO.deptType = GSBaseConstants.BALANCE_ORDERDEPT_TYPE;
                // tBalInfoVO.actualBalanceDept = aForm.getOrderDeptId();
                tBalInfoVO.payType = GSBaseConstants.RECEIVE_TYPE;
                tBalanceList.add(tBalInfoVO);
            } else {
                GSLogWriter.error(this, GSException.E40002_MSG);
                throw new GSException(GSException.E40002, GSException.E40002_MSG);
            }
            // 新增对帐数据
            if (tBalanceList.size() > 0) {
                for (int i = 0; i < tBalanceList.size(); i++) {
                    GSBalanceInfoVO tVO = (GSBalanceInfoVO) tBalanceList.get(i);
                    tVO.startDate = DateUtil.formatDate(aForm.getBalanceStrDate());
                    tVO.endDate = DateUtil.formatDate(aForm.getBalanceEndDate());
                    tVO.operatorId = tOperBean.getGs_oper_id();
                    tVO.operateDate = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                    tVO.balanceFlag = GSBaseConstants.UNBALANCE_STATUS;
                    tFlag = tBalMsgDAO.insertBalanceInfo(tVO, tConn);
                    if (!tFlag) {
                        GSLogWriter.error(this, "写结算信息表失败");
                        tConn.rollback();
                        break;
                    }
                }
                if (tFlag) {
                    GSLogWriter.info(this, "成功写入新数据到结算信息表");
                }
            }
            // 修改供应商对帐数据
            if (tFlag) {
                if (tUpdateBalList.size() > 0) {
                    for (int i = 0; i < tUpdateBalList.size(); i++) {
                        String[] tBalMsg = (String[]) tUpdateBalList.get(i);
                        tFlag = tBalMsgDAO.updateBalanceSum(tConn, tBalMsg, tEndDate1, tOperBean.getGs_oper_id());
                        if (!tFlag) {
                            GSLogWriter.error(this, "修改结算信息表中已存在供应商结算金额失败");
                            tConn.rollback();
                            break;
                        }
                    }
                    if (tFlag) {
                        GSLogWriter.info(this, "成功修改结算信息表中供应商结算金额");
                    }
                }
            } else {
                throw new GSException(GSException.E00001, GSException.E00001);
            }
            if (tBalanceList.size() < 1 && tUpdateBalList.size() < 1) {
                GSLogWriter.error(this, "无可写入到结算信息表的数据，需检查数据或程序");
                throw new GSException("无可写入到结算信息表的数据，需检查数据或程序");
            } else {
                if (tFlag) {
                    tConn.commit();
                    GSLogWriter.info(this, "成功新增或修改结算信息表中供应商的结算金额");
                }
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        } finally {
            try {
                if (tConn != null) {
                    tConn.setAutoCommit(true);
                }
                GSBaseDAO.close(tConn);
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return tFlag;
    }

    /**
     * 查询结算信息(暂不用)
     * 
     * @param aVO
     * @param aList
     * @return
     * @throws GSException
     */
    public ArrayList getBalanceInfo(GSBalanceManageQueryVO aVO, ArrayList aList) throws GSException {
        ArrayList tRs = new ArrayList();
        GSBalanceMsgDAO tBalDAO = new GSBalanceMsgDAO();
        // 查询结算信息
        ArrayList tList = tBalDAO.queryBalanceMsg(aVO, aList);
        ArrayList tWorkCorpList = new ArrayList();
        if (tList.size() > 0) {
            int size = 0;
            String temp = "";
            // 将订货单位为运营公司的先提取出来，便于稍后将存在的下级单位的结算信息与当前单位的结算信息按顺序放在一起
            for (int i = 0; i < tList.size(); i++) {
                GSBalanceManageQueryResultVO tVO = (GSBalanceManageQueryResultVO) tList.get(i);
                if (tVO.deptId.length() == 4 && !tVO.deptId.substring(0, 2).equals("00") && tVO.deptId.substring(2, 4).equals("00")) {
                    tWorkCorpList.add(tVO.deptId);
                }
            }
            for (int i = 0; i < tList.size(); i++) {
                GSBalanceManageQueryResultVO tVO1 = (GSBalanceManageQueryResultVO) tList.get(i);
                String[] tStr = new String[10];
                tStr[0] = tVO1.deptId;
                tStr[1] = tVO1.deptName;
                tStr[2] = tVO1.deptCategory;
                tStr[3] = tVO1.balanceMonth.substring(0, 4);
                if (tVO1.balanceMonth.substring(4, 5).equals("0")) {
                    tStr[4] = tVO1.balanceMonth.substring(5, 6);
                } else
                    tStr[4] = tVO1.balanceMonth.substring(4, 6);

                tStr[5] = StringUtils.formatEDouble(tVO1.balanceSum, 4);
                tStr[6] = tVO1.balanceSign;
                tStr[7] = tVO1.upperDeptId;
                if (tVO1.upperDeptId.equals("")) {// 供应商
                    tStr[8] = "";
                    tStr[9] = "1"; // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                    tRs.add(tStr);
                } else {// 订货单位
                    // 如果是运营公司则查询是否还有下级机构，若存在则将下级机构的结算信息与当前机构的结算信息按顺序放在一起
                    if (tVO1.deptId.substring(2, 4).equals("00") && !tVO1.deptId.substring(0, 2).equals("00")) {
                        tRs.add(tStr);
                        size = 1;
                        for (int j = 0; j < tList.size(); j++) {
                            GSBalanceManageQueryResultVO tVO2 = (GSBalanceManageQueryResultVO) tList.get(j);
                            if (tVO1.deptId.equals(tVO2.upperDeptId)) {
                                size = size + 1;
                                String[] tStr2 = new String[10];
                                tStr2[0] = tVO2.deptId;
                                tStr2[1] = tVO2.deptName;
                                tStr2[2] = tVO2.deptCategory;
                                tStr2[3] = tVO2.balanceMonth.substring(0, 4);
                                if (tVO2.balanceMonth.substring(4, 5).equals("0")) {
                                    tStr2[4] = tVO1.balanceMonth.substring(5, 6);
                                } else
                                    tStr2[4] = tVO1.balanceMonth.substring(4, 6);
                                tStr2[5] = StringUtils.formatEDouble(tVO2.balanceSum, 4);
                                tStr2[6] = tVO2.balanceSign;
                                tStr2[7] = tVO2.upperDeptId;
                                tStr2[8] = tVO1.deptName;
                                tRs.add(tStr2);
                            }
                        }
                        tStr[8] = tStr[1];
                        tStr[9] = String.valueOf(size); // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                    } else {
                        if (isExist(tVO1.upperDeptId, tWorkCorpList)) {
                            continue; // 该订货单位的结算信息已被提取并放入到结果集中
                        } else { // 修理厂级的结算信息处理
                            if (temp.equals(tVO1.upperDeptId)) {
                                // size = size + 1;
                            } else {
                                size = 1;
                                if (i == tList.size() - 1) {
                                    // size = 1;
                                    tStr[9] = String.valueOf(size); // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                                } else {
                                    for (int j = i + 1; j < tList.size(); j++) {
                                        GSBalanceManageQueryResultVO tVO2 = (GSBalanceManageQueryResultVO) tList.get(j);
                                        if (tVO2.upperDeptId.equals(tVO1.upperDeptId)) {
                                            size = size + 1;
                                        }
                                    }
                                    tStr[9] = String.valueOf(size); // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                                }
                                temp = tVO1.upperDeptId;
                            }
                            GSOrganizationDAO tOrgDAO = new GSOrganizationDAO();
                            tStr[8] = tOrgDAO.queryOrgName(tVO1.upperDeptId);
                            tRs.add(tStr);
                        }
                    }
                }
            }
        }

        return tRs;
    }

    public ArrayList getBalanceInfo2(GSBalanceManageQueryVO aVO, ArrayList aList) throws GSException {
        ArrayList tRs = new ArrayList();
        GSBalanceMsgDAO tBalDAO = new GSBalanceMsgDAO();
        // 查询结算信息
        ArrayList tList = tBalDAO.queryBalanceMsg(aVO, aList);
        if (tList.size() > 0) {
            int size = 0;
            int j = 0;
            for (int i = 0; i < tList.size(); i++) {
                GSBalanceManageQueryResultVO tVO1 = (GSBalanceManageQueryResultVO) tList.get(i);
                if (j >= i && j != 0) {
                    continue;
                }
                String[] tStr = new String[12];
                tStr[0] = tVO1.deptId;
                tStr[1] = tVO1.deptName;
                tStr[2] = tVO1.deptCategory;
                tStr[3] = tVO1.balanceMonth.substring(0, 4);
                if (tVO1.balanceMonth.substring(4, 5).equals("0")) {
                    tStr[4] = tVO1.balanceMonth.substring(5, 6);
                } else
                    tStr[4] = tVO1.balanceMonth.substring(4, 6);

                tStr[5] = StringUtils.formatEDouble(tVO1.balanceSum, 4);
                tStr[6] = tVO1.balanceSign;
                tStr[7] = tVO1.upperDeptId;
                if (tVO1.deptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)) {
                    if (tVO1.actualBalanceDept != null && !tVO1.actualBalanceDept.equals("")) {
                        GSOrganizationDAO tOrgDAO = new GSOrganizationDAO();
                        String tActOrgName = tOrgDAO.queryOrgName(tVO1.actualBalanceDept);
                        tStr[8] = tVO1.actualBalanceDept;
                        tStr[10] = tActOrgName;
                        size = 1;
                        tRs.add(tStr);
                        if (i < tList.size() - 1) {
                            for (j = i + 1; j < tList.size(); j++) {
                                GSBalanceManageQueryResultVO tVO2 = (GSBalanceManageQueryResultVO) tList.get(j);
                                if (tVO2.actualBalanceDept.equals(tVO1.actualBalanceDept)) {
                                    size = size + 1;
                                    String[] tStr2 = new String[10];
                                    tStr2[0] = tVO2.deptId;
                                    tStr2[1] = tVO2.deptName;
                                    tStr2[2] = tVO2.deptCategory;
                                    tStr2[3] = tVO2.balanceMonth.substring(0, 4);
                                    if (tVO2.balanceMonth.substring(4, 5).equals("0")) {
                                        tStr2[4] = tVO1.balanceMonth.substring(5, 6);
                                    } else
                                        tStr2[4] = tVO1.balanceMonth.substring(4, 6);
                                    tStr2[5] = StringUtils.formatEDouble(tVO2.balanceSum, 4);
                                    tStr2[6] = tVO2.balanceSign;
                                    tStr2[7] = tVO2.upperDeptId;
                                    tStr2[8] = tVO1.actualBalanceDept;
                                    tRs.add(tStr2);
                                } else {
                                    j--;
                                    break;
                                }
                            }
                        }
                        tStr[9] = String.valueOf(size); // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                    } else {
                        tStr[8] = "";
                        tStr[9] = "1";
                        tStr[10] = "";
                        tRs.add(tStr);
                    }
                } else {
                    tStr[8] = tVO1.deptId;
                    tStr[9] = "1";
                    tStr[10] = "";
                    tRs.add(tStr);
                }
            }
        }

        return tRs;
    }

    public ArrayList getBalanceInfo3(GSBalanceManageQueryVO aVO, ArrayList aList) throws GSException {
        ArrayList tRs = new ArrayList();
        GSBalanceMsgDAO tBalDAO = new GSBalanceMsgDAO();
        // 查询结算信息
        ArrayList tList = tBalDAO.queryBalanceMsg3(aVO, aList);
        if (tList.size() > 0) {
            int size = 0;
            int j = 0;
            for (int i = 0; i < tList.size(); i++) {
                GSBalanceManageQueryResultVO tVO1 = (GSBalanceManageQueryResultVO) tList.get(i);
                if (j >= i && j != 0) {
                    continue;
                }
                String[] tStr = new String[12];
                tStr[0] = tVO1.deptId;
                tStr[1] = tVO1.deptName;
                tStr[2] = tVO1.deptCategory;
                tStr[3] = tVO1.balanceMonth.substring(0, 4);
                if (tVO1.balanceMonth.substring(4, 5).equals("0")) {
                    tStr[4] = tVO1.balanceMonth.substring(5, 6);
                } else
                    tStr[4] = tVO1.balanceMonth.substring(4, 6);

                tStr[5] = StringUtils.formatEDouble(tVO1.balanceSum, 4);
                tStr[6] = tVO1.balanceSign;
                tStr[7] = tVO1.upperDeptId;
                if (tVO1.deptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)) {
                    if (tVO1.actualBalanceDept != null && !tVO1.actualBalanceDept.equals("")) {
                        GSOrganizationDAO tOrgDAO = new GSOrganizationDAO();
                        String tActOrgName = tOrgDAO.queryOrgName(tVO1.actualBalanceDept);
                        tStr[8] = tVO1.actualBalanceDept;
                        tStr[10] = tActOrgName;
                        tStr[11] = tVO1.balanceMsg;
                        size = 1;
                        tRs.add(tStr);
                        if (i < tList.size() - 1) {
                            for (j = i + 1; j < tList.size(); j++) {
                                GSBalanceManageQueryResultVO tVO2 = (GSBalanceManageQueryResultVO) tList.get(j);
                                if (tVO2.actualBalanceDept.equals(tVO1.actualBalanceDept)) {
                                    size = size + 1;
                                    String[] tStr2 = new String[10];
                                    tStr2[0] = tVO2.deptId;
                                    tStr2[1] = tVO2.deptName;
                                    tStr2[2] = tVO2.deptCategory;
                                    tStr2[3] = tVO2.balanceMonth.substring(0, 4);
                                    if (tVO2.balanceMonth.substring(4, 5).equals("0")) {
                                        tStr2[4] = tVO1.balanceMonth.substring(5, 6);
                                    } else
                                        tStr2[4] = tVO1.balanceMonth.substring(4, 6);
                                    tStr2[5] = StringUtils.formatEDouble(tVO2.balanceSum, 4);
                                    tStr2[6] = tVO2.balanceSign;
                                    tStr2[7] = tVO2.upperDeptId;
                                    tStr2[8] = tVO1.actualBalanceDept;
                                    tStr2[9] = tVO2.balanceMsg;
                                    tRs.add(tStr2);
                                } else {
                                    j--;
                                    break;
                                }
                            }
                        }
                        tStr[9] = String.valueOf(size); // 计算上级单位相同的结算数据笔数，用于在页面将结算单位栏合并显示而
                    } else {
                        tStr[8] = "";
                        tStr[9] = "1";
                        tStr[10] = "";
                        tStr[11] = tVO1.balanceMsg;
                        tRs.add(tStr);
                    }
                } else {
                    tStr[8] = tVO1.deptId;
                    tStr[9] = "1";
                    tStr[10] = "";
                    tStr[11] = tVO1.balanceMsg;
                    tRs.add(tStr);
                }
            }
        }

        return tRs;
    }

    public ArrayList getBalanceInfo4(GSBalanceManageQueryVO aVO) throws GSException {
        ArrayList tRs = new ArrayList();
        GSBalanceMsgDAO tBalDAO = new GSBalanceMsgDAO();
        // 查询结算信息
        ArrayList tList = tBalDAO.queryBalanceMsg4(aVO);
        GSProviderProcessor pro = new GSProviderProcessor();
        for (int i = 0; i < tList.size(); i++) {
            GSBalanceManageQueryResultVO tVO1 = (GSBalanceManageQueryResultVO) tList.get(i);
            String[] tStr = new String[12];
            tStr[0] = tVO1.deptId;
            tStr[1] = tVO1.deptName;
            tStr[2] = tVO1.deptCategory;
            tStr[3] = tVO1.balanceMonth.substring(0, 4);
            if (tVO1.balanceMonth.substring(4, 5).equals("0")) {
                tStr[4] = tVO1.balanceMonth.substring(5, 6);
            } else
                tStr[4] = tVO1.balanceMonth.substring(4, 6);

            tStr[5] = StringUtils.formatEDouble(tVO1.balanceSum, 4);
            tStr[6] = tVO1.balanceSign;
            tStr[7] = tVO1.upperDeptId;
            tStr[8] = tVO1.actualBalanceDept;
            tStr[9] = "1";
            tStr[10] = pro.getProviderById(tVO1.deptId).getGs_provider_name();
            tStr[11] = tVO1.balanceMsg;
            tRs.add(tStr);
        }
        return tRs;
    }

    /**
     * 判断是否该订货单位存在于列表中
     * 
     * @param aStr
     * @param aWorkCorpList
     * @return
     * @throws GSException
     */
    private boolean isExist(String aStr, ArrayList aWorkCorpList) throws GSException {
        boolean tFlag = false;
        for (int i = 0; i < aWorkCorpList.size(); i++) {
            String temp = (String) aWorkCorpList.get(i);
            if (temp.equals(aStr)) {
                tFlag = true;
                break;
            }
        }
        return tFlag;
    }

    /**
     * 作废删除
     * 
     * @param aDeptId
     * @param aBalanceYM
     * @param aOper
     * @return
     * @throws GSException
     */
    public boolean abolishBalanceInfo(String aDeptId, String aBalanceYM, GSOperatorBean aOper) throws GSException {
        boolean tFlag = false;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        Connection tConn = null;
        try {
            tConn = tBalMsgDAO.getConnetion();
            tConn.setAutoCommit(false);
            // 查询结算信息
            ArrayList tList = tBalMsgDAO.queryBalanceInfo(aDeptId, aBalanceYM);
            GSBalanceMsgBean tBean = null;
            if (tList.size() > 0) {
                tBean = (GSBalanceMsgBean) tList.get(0);
            }
            // 删除该笔结算数据
            tFlag = tBalMsgDAO.abolishBalanceMsg(tConn, aDeptId, aBalanceYM);
            if (tFlag) {
                // 取得结算区间的结束日期
                String balanceEndDate = tBean.getGs_end_date();
                balanceEndDate = balanceEndDate.substring(0, 4) + balanceEndDate.substring(5, 7) + balanceEndDate.substring(8, 10);
                // 查询出结算信息对应的订单明细
                GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
                tList = tOrderDtlDAO.queryBalancedDetail(aDeptId, aBalanceYM, balanceEndDate);
                ArrayList tSubmitList = new ArrayList();// 通知交易平台作废明细列表
                ArrayList tProviderList = new ArrayList();
                if (tList.size() > 0) {
                    String tProviderId = "";
                    double tProviderAmt = 0;
                    String tProviderBalYM = "";
                    for (int i = 0; i < tList.size(); i++) {
                        GSOrderDetailBean tDtlBean = (GSOrderDetailBean) tList.get(i);
                        if (!tProviderId.equals(tDtlBean.getGs_provider_id())) {
                            if (!tProviderId.equals("")) {
                                String[] tStr = new String[3];
                                tStr[0] = tProviderId;
                                tStr[1] = String.valueOf(tProviderAmt);
                                tStr[2] = tProviderBalYM;
                                tProviderList.add(tStr);
                            }
                            tProviderId = tDtlBean.getGs_provider_id();
                            tProviderBalYM = tDtlBean.getGs_balance_month_provider();
                            tProviderAmt = tDtlBean.getGs_signin_count() * tDtlBean.getGs_goods_unitprice();
                        } else {
                            tProviderAmt = tProviderAmt + tDtlBean.getGs_signin_count() * tDtlBean.getGs_goods_unitprice();
                        }
                        if (i == tList.size() - 1) {
                            String[] tStr = new String[3];
                            tStr[0] = tProviderId;
                            tStr[1] = String.valueOf(tProviderAmt);
                            tStr[2] = tProviderBalYM;
                            tProviderList.add(tStr);
                        }
                        GSOrderDetailBean tOrdDtlBean = new GSOrderDetailBean();
                        tOrdDtlBean.setGs_order_detail_id(tDtlBean.getGs_order_detail_id());
                        tOrdDtlBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS);
                        tOrdDtlBean.setGs_is_prov_balanced(GSBaseConstants.UNBALANCE_STATUS);
                        tOrdDtlBean.setGs_balance_month(null);
                        tOrdDtlBean.setGs_balance_month_provider(null);
                        tOrdDtlBean.setGs_order_detail_status(GSBaseConstants.ORDER_BLANK_OUT);
                        tOrdDtlBean.setGs_lastmodifer_id(aOper.getGs_oper_id());
                        tOrdDtlBean.setGs_lastmodify_contents("结算作废操作");
                        String tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                        tOrdDtlBean.setGs_lastmodify_date(tCurDT);
                        tOrdDtlBean.setGs_cancel_cause("结算作废删除"); // 取消原因
                        tOrdDtlBean.setGs_cancel_date(tCurDT);
                        tOrdDtlBean.setGs_cancel_person(aOper.getGs_oper_id());
                        tSubmitList.add(tOrdDtlBean);
                        // 逐笔修改订单明细状态
                        tFlag = tOrderDtlDAO.updateOrderDetailStatus(tOrdDtlBean, tConn, GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                        if (!tFlag) {
                            tConn.rollback();
                            GSLogWriter.error(this, "修改订单明细状态失败");
                            break;
                        }
                    }
                    if (tFlag) {
                        for (int i = 0; i < tProviderList.size(); i++) {
                            String[] tProvider = (String[]) tProviderList.get(i);
                            // 查询供应商在该月份的结算信息
                            ArrayList tempProvider = tBalMsgDAO.queryBalanceInfo(tProvider[0], tProvider[2]);
                            if (tempProvider.size() > 0) {
                                GSBalanceMsgBean tBalBean = (GSBalanceMsgBean) tempProvider.get(0);
                                // 如果数据库中该供应商的结算金额大于当前待作废金额，则从总金额中减去此笔金额
                                DecimalFormat tDecFmt = new DecimalFormat("###############.####");
                                double temp1 = Double.parseDouble(tDecFmt.format(tBalBean.getGs_balance_sum()));
                                double temp2 = Double.parseDouble(tDecFmt.format(Double.parseDouble(tProvider[1])));
                                // if(tBalBean.getGs_balance_sum() -
                                // Double.parseDouble(tProvider[1]) == 0){
                                if (temp1 - temp2 > 0) {
                                    double amt = temp1 - temp2;
                                    tProvider[1] = String.valueOf(amt);
                                    tFlag = tBalMsgDAO.updateBalanceSum(tConn, tProvider, aBalanceYM, aOper.getGs_oper_id());
                                } else {
                                    // 如果数据库中该供应商的结算金额小于或等于当前待作废金额，则从结算表中删除此笔数据
                                    tFlag = tBalMsgDAO.abolishBalanceMsg(tConn, tProvider[0], aBalanceYM);
                                }
                                if (!tFlag) {
                                    // tConn.rollback();
                                    GSLogWriter.error(this, "作废供应商结算信息失败");
                                    throw new GSException(GSException.E40004, GSException.E40004_MSG);
                                }
                            } else {
                                GSLogWriter.error(this, "查询不到该供应商的结算信息");
                                throw new GSException("查询不到该供应商的结算信息");
                            }
                            GSPayReceiveAbleDAO tPayRecDAO = new GSPayReceiveAbleDAO();
                            ArrayList tempPayRevInfo = tPayRecDAO.queryPayRecvInfo(tConn, tProvider[2], tProvider[0]);
                            if (tempPayRevInfo.size() == 1) {
                                GSPayReceiveAbleBean tPayRecBean = (GSPayReceiveAbleBean) tempPayRevInfo.get(0);
                                tFlag = tPayRecDAO.deletePayRecvInfo(tConn, tPayRecBean);
                                if (!tFlag) {
                                    // tConn.rollback();
                                    GSLogWriter.error(this, "作废供应商结算信息时删除已结算的应收应付信息失败");
                                    throw new GSException(GSException.E40008, GSException.E40008_MSG);
                                }
                            } else {
                                GSLogWriter.info(this, "无已结算的应收应付信息");
                            }
                        }
                        if (tFlag) {
                            // 通知交易平台
                            String tRs = this.submitAbolishDetailToApep(tSubmitList);
                            if (tRs.equals("1")) {
                                tConn.commit();
                                GSLogWriter.info(this, "作废删除修改订单明细状态并向交易平台发送信息成功");
                            } else {
                                GSLogWriter.error(this, "向交易平台发送订单明细作废信息失败");
                                throw new GSException("向交易平台发送订单明细作废信息失败");
                            }
                        }
                    }
                } else {
                    GSLogWriter.error(this, GSException.E40007_MSG);
                    throw new GSException(GSException.E40007, GSException.E40007_MSG);
                }
            } else {
                // tConn.rollback();
                GSLogWriter.error(this, GSException.E40003);
                throw new GSException(GSException.E40003, GSException.E40003_MSG);
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        } finally {
            try {
                if (tConn != null) {
                    tConn.setAutoCommit(true);
                }
                GSBaseDAO.close(tConn);
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return tFlag;
    }

    /**
     * 进入生成应收页面
     * 
     * @param aVO
     * @return
     * @throws GSException
     */
    public HashMap productRecvInfo(GSBalanceManagePayReceiveVO aVO) throws GSException {
        HashMap tMap = new HashMap();

        GSBargainDAO tBargDAO = new GSBargainDAO();

        // 查询合同信息
        ArrayList tList = tBargDAO.queryBargainByCustom(aVO.deptCategory, aVO.deptId);
        ArrayList tBargainList = new ArrayList();
        if (tList.size() > 0) {
            String[] tStr = null;
            String tBgnSerial = "";
            String tBgnId = "";
            String tBgnType = "";
            String tBgnCont = "";
            String tBgcCont = "";
            for (int i = 0; i < tList.size(); i++) {
                GSBargainAndChargeVO tVO = (GSBargainAndChargeVO) tList.get(i);
                tBgnId = tVO.bgnId;
                tBgnSerial = tVO.bgnSerial;
                tBgnType = tVO.bgnType;
                tBgnCont = tVO.bgnContent;
                ArrayList tChargeList = tBargDAO.queryBargainCharge(tBgnId); // 根据序号查询合同费用信息
                if (tChargeList.size() > 0) {
                    for (int j = 0; j < tChargeList.size(); j++) {
                        GSBargainChargeBean tChargeBean = (GSBargainChargeBean) tChargeList.get(j);
                        if (j == 0) {
                            tBgcCont = tChargeBean.getGs_bgc_type() + ":" + tChargeBean.getGs_bgc_content();
                        } else {
                            tBgcCont = tBgcCont + ";" + tChargeBean.getGs_bgc_type() + ":" + tChargeBean.getGs_bgc_content();
                        }
                    }
                }
                if (i == tList.size() - 1) {
                    tStr = new String[5];
                    tStr[0] = tBgnId; // 序号
                    tStr[1] = tBgnSerial; // 编号
                    tStr[2] = tBgnType;
                    tStr[3] = tBgnCont;
                    tStr[4] = tBgcCont;
                    tBargainList.add(tStr);
                } else if (i < tList.size() - 1) {
                    GSBargainAndChargeVO tVO2 = (GSBargainAndChargeVO) tList.get(i + 1);
                    if (tVO2 != null && !tVO2.bgnSerial.equals(tBgnSerial)) {
                        tStr = new String[5];
                        tStr[0] = tBgnId; // 序号
                        tStr[1] = tBgnSerial; // 编号
                        tStr[2] = tBgnType;
                        tStr[3] = tBgnCont;
                        tStr[4] = tBgcCont;
                        tBargainList.add(tStr);
                        tBgcCont = "";
                    }
                }
            }
            // 将合同信息放入HASHMAP中
            tMap.put("bargain", tBargainList);
        }
        // 查询费用类型
        GSBalanceFeeDAO tBalFeeDAO = new GSBalanceFeeDAO();
        ArrayList tBalFeeList = tBalFeeDAO.queryAllFeeType();
        tMap.put("feetype", tBalFeeList);
        Connection tConn = null;
        GSOrganizationDAO tOrgDAO = new GSOrganizationDAO();
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        ArrayList tBalList = new ArrayList();
        try {
            tConn = tOrgDAO.getConnetion();
            if (aVO.deptId.substring(2, 4).equals("00")) {

                tList = tOrgDAO.getSubOrg(tConn, aVO.deptId);
                if (tList.size() > 0) {
                    for (int i = 0; i < tList.size(); i++) {
                        GSOrganizationBean tOrgBean = (GSOrganizationBean) tList.get(i);
                        ArrayList temp = tBalMsgDAO.queryBalanceInfoByOrderDept(tOrgBean.getGs_org_id(), aVO.balanceYM, GSBaseConstants.UNBALANCE_STATUS);
                        if (temp.size() == 1) {
                            tBalList.add(temp.get(0));
                        }
                    }
                    if (tBalList.size() > 0) {
                        tMap.put("suborg", tBalList);
                    } else {
                        GSLogWriter.info("下级组织在该月份暂无结算信息");
                    }
                } else {
                    GSLogWriter.info("无下级组织");
                }
            }
            // 查询付款日期
            GSBargainDAO tBargainDAO = new GSBargainDAO();
            String tWeek = tBargainDAO.queryMaxBgnWeek(aVO.deptId, aVO.deptCategory);
            if (tWeek.equals("")) {
                tWeek = "60";
            }
            String tRecDate = DateUtil.getNextUpDay(Integer.parseInt(tWeek));
            tMap.put("recvday", DateUtil.formateDateTime(tRecDate));
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        } finally {
            try {
                GSBaseDAO.close(tConn);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String tOrgName = tOrgDAO.queryOrgName(aVO.deptId);
        tMap.put("org", aVO.deptId);
        tMap.put("orgname", tOrgName);
        tMap.put("balanceym", aVO.balanceYM);
        tMap.put("deptcategory", aVO.deptCategory);
        tMap.put("balancsum", StringUtils.formatEDouble(aVO.balanceSum, 4));
        return tMap;
    }

    /**
     * 应收应付处理
     * 
     * @param aOperBean
     * @param aList
     * @return
     * @throws GSException
     */
    public boolean saveRecvPayMsg(GSOperatorBean aOperBean, ArrayList aList) throws GSException {
        boolean tFlag = false;
        Connection tConn = null;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        try {
            tConn = tBalMsgDAO.getConnetion();
            tConn.setAutoCommit(false);
            GSBalanceManagePayRecvSaveVO tVO = (GSBalanceManagePayRecvSaveVO) aList.get(0);
            if (tVO.orgCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)) {// 生成应收信息处理
                tFlag = receiveProcess(tVO, aList, aOperBean, tConn);
            } else if (tVO.orgCategory.equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)) {// 生成应付信息处理
                tFlag = payProcess(tVO, aList, aOperBean, tConn);
            }
            if (tFlag) {
                tConn.commit();
            } else {
                tConn.rollback();
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw new GSException(GSException.E00001, GSException.E00001_MSG);
        } finally {
            if (tConn != null) {
                try {
                    tConn.setAutoCommit(true);
                    GSBaseDAO.close(tConn);
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
        }
        return tFlag;
    }

    /**
     * 应收处理 (只出现在领用明细记录里)
     * 
     * @param aVO
     * @param aList
     * @param aOperBean
     * @param aConn
     * @return
     * @throws GSException
     */
    private boolean receiveProcess(GSBalanceManagePayRecvSaveVO aVO, ArrayList aList, GSOperatorBean aOperBean, Connection aConn) throws GSException {
        boolean tFlag;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        GsStocksDao stocksdao = new GsStocksDao();
        GSPayReceiveAbleDAO tPayRecvDAO = new GSPayReceiveAbleDAO();
        try {
            // 查询该机构在结算表中的结算信息
            ArrayList tBalMsgList = tBalMsgDAO.queryBalanceInfoByOrderDept(aVO.orgId, aVO.balancYM, GSBaseConstants.UNBALANCE_STATUS);
            if (tBalMsgList.size() == 1) {
                String endDate = ((GSBalanceMsgBean) tBalMsgList.get(0)).getGs_end_date();
                endDate = DateUtil.splitSpecChar(endDate);
                String[] tStr = new String[5];
                tStr[0] = GSBaseConstants.BALANCE_STATUS;
                tStr[1] = aOperBean.getGs_oper_id();
                tStr[2] = aVO.orgId;
                tStr[3] = aVO.balancYM;
                tStr[4] = aVO.orgId; // 实际结算单位
                // 修改该机构的该笔结算信息状态为已结算
                tFlag = tBalMsgDAO.updateBalanceStatus(aConn, tStr);
                if (tFlag) {
                    GSLogWriter.info(this, "修改应收结算状态成功");
                    // 查询该机构对应的领用明细信息
                    String[] str = { aVO.orgId, aVO.balancYM, "org" };
                    ArrayList stockslist = stocksdao.getStocksDetailBalanceResult2(str);
                    if (stockslist.size() > 0) {
                        // 修改该机构该月份结算信息所对应的压库明细状态为已完成
                        String cont = "[ " + DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss") + " 生成应收]";
                        for (int i = 0; i < stockslist.size(); i++) {
                            GSStocksOtherBean sobean = (GSStocksOtherBean) stockslist.get(i);
                            if (sobean.getGs_balance_mode().equals(GSBaseConstants.BALANCE_MODE1)) {
                                tFlag = stocksdao.updateStocksDetailState4(aConn, sobean.getGs_detail_id(), "3", "3", "3", cont);// 如果是买断生成应收全部完成
                            } else {
                                tFlag = stocksdao.updateStocksDetailState6(aConn, "3", sobean.getGs_detail_id(), "4", cont);// 4压库结算已完成应收
                            }
                            if (!tFlag) {
                                GSLogWriter.error(this, "修改压库明细状态失败");
                                break;
                            }
                        }
                    } else {
                        GSLogWriter.error(this, "根据结算数据未查到对应的领用明细信息");
                        throw new GSException("根据结算数据未查到对应的领用明细信息");
                    }
                    if (tFlag) {
                        // 新增应收数据到应收应付信息表
                        for (int m = 0; m < aList.size(); m++) {
                            aVO = (GSBalanceManagePayRecvSaveVO) aList.get(m);
                            GSPayReceiveAbleBean tPayRecvAbleBean = new GSPayReceiveAbleBean();
                            tPayRecvAbleBean.setGs_workcorp_id(aVO.orgId);
                            tPayRecvAbleBean.setGs_workcorp_category(aVO.orgCategory);
                            tPayRecvAbleBean.setGs_balance_month(aVO.balancYM);
                            tPayRecvAbleBean.setGs_notes(aVO.notes);
                            tPayRecvAbleBean.setGs_workcorp_level(aVO.orgLevel);
                            tPayRecvAbleBean.setGs_workcorp_id_group(aVO.subOrgId);
                            tPayRecvAbleBean.setGs_fee_type_id(aVO.costType);
                            tPayRecvAbleBean.setGs_pay_date(aVO.recvDate);
                            tPayRecvAbleBean.setGs_pay_type(aVO.payType);
                            tPayRecvAbleBean.setGs_balance_need(aVO.balSum);
                            tPayRecvAbleBean.setGs_balance_undone(aVO.balSum);
                            tPayRecvAbleBean.setGs_pay_status(GSBaseConstants.UNPAY);
                            tPayRecvAbleBean.setGs_principal(aVO.principal);
                            tPayRecvAbleBean.setGs_operator_id(aOperBean.getGs_oper_id());
                            String tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                            tPayRecvAbleBean.setGs_operator_date(tCurDT);
                            String tCurT = DateUtil.getCurrentDate("MM-dd hh:mm:ss");
                            tPayRecvAbleBean.setGs_offset_date("1970" + "-" + tCurT);
                            tPayRecvAbleBean.setGs_receiveable_id(GenRandNum.genDTRandNum());
                            tFlag = tPayRecvDAO.insertPayReceiveInfo(tPayRecvAbleBean, aConn);
                            if (!tFlag) {
                                GSLogWriter.error(this, "新增应收信息到应收应付表失败");
                                break;
                            }
                        }
                        if (tFlag) {
                            GSLogWriter.info(this, "应收操作成功完成");
                        }
                    }
                } else {
                    GSLogWriter.error(this, "运营公司结算信息状态修改失败");
                }
            } else {
                GSLogWriter.error(this, GSException.E40005_MSG);
                throw new GSException(GSException.E40005, GSException.E40005_MSG);
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            throw new GSException(e.toString());
        }
        return tFlag;
    }

    /**
     * 应付处理
     * 
     * @param aVO
     * @param aList
     * @param aOperBean
     * @param aConn
     * @return
     * @throws GSException
     */
    private boolean payProcess(GSBalanceManagePayRecvSaveVO aVO, ArrayList aList, GSOperatorBean aOperBean, Connection aConn) throws GSException {
        boolean tFlag = false;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        GsStocksDao stocksdao = new GsStocksDao();
        GSPayReceiveAbleDAO tPayRecvDAO = new GSPayReceiveAbleDAO();
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        try {
            // 查询该供应商在结算表中的结算信息
            ArrayList tBalMsgList = tBalMsgDAO.queryBalanceInfoByOrderDept(aVO.orgId, aVO.balancYM, GSBaseConstants.UNBALANCE_STATUS);
            if (tBalMsgList.size() == 1) {
                String endDate = ((GSBalanceMsgBean) tBalMsgList.get(0)).getGs_end_date();
                endDate = DateUtil.splitSpecChar(endDate);
                String[] tStr = new String[5];
                tStr[0] = GSBaseConstants.BALANCE_STATUS;
                tStr[1] = aOperBean.getGs_oper_id();
                tStr[2] = aVO.orgId;
                tStr[3] = aVO.balancYM;
                tStr[4] = aVO.orgId;
                // 修改该机构的该笔结算信息状态为已结算
                tFlag = tBalMsgDAO.updateBalanceStatus(aConn, tStr);
                if (tFlag) {
                    GSLogWriter.info(this, "修改供应商结算状态成功");
                    // 查询该机构对应的领用压库结算明细信息
                    String[] str = { aVO.orgId, aVO.balancYM, "prov", "1" };
                    ArrayList stockslist = stocksdao.getStocksDetailBalanceResult2(str);
                    if (stockslist.size() > 0) {
                        // 修改该机构该月份结算信息所对应的压库明细状态为已完成
                        String cont = "[ " + DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss") + " 生成应付]";
                        for (int i = 0; i < stockslist.size(); i++) {
                            GSStocksOtherBean sobean = (GSStocksOtherBean) stockslist.get(i);
                            tFlag = stocksdao.updateStocksDetailState7(aConn, "3", sobean.getGs_detail_id(), "4", cont);// 4压库结算已完成应付
                            if (!tFlag) {
                                GSLogWriter.error(this, "修改压库明细状态失败");
                                break;
                            }
                        }
                    }
                    // 查询该机构对应的订单明细信息
                    ArrayList tOrderDetailList = tOrderDtlDAO.queryDetailAssociatedBalanced(aVO.orgId, endDate, aVO.balancYM);
                    if (tOrderDetailList.size() > 0) {
                        for (int i = 0; i < tOrderDetailList.size(); i++) {
                            GSBalancedDetailProvResultVO tOrderDtlBean = (GSBalancedDetailProvResultVO) tOrderDetailList.get(i);
                            GSOrderDetailBean tUpdateOrderDtlBean = new GSOrderDetailBean();
                            tUpdateOrderDtlBean.setGs_order_detail_id(tOrderDtlBean.orderDetailId);
                            tUpdateOrderDtlBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
                            tUpdateOrderDtlBean.setGs_lastmodify_contents("生成应付");
                            tUpdateOrderDtlBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss"));
                            tUpdateOrderDtlBean.setGs_order_detail_status(GSBaseConstants.ORDER_FINISH);
                            tUpdateOrderDtlBean.setGs_is_balanced(GSBaseConstants.BALANCE_STATUS);
                            tUpdateOrderDtlBean.setGs_is_prov_balanced(GSBaseConstants.BALANCE_STATUS);
                            tUpdateOrderDtlBean.setGs_balance_month(tOrderDtlBean.balancemonth);
                            tUpdateOrderDtlBean.setGs_balance_month_provider(tOrderDtlBean.balancemonthprov);
                            // 修改该机构该月份结算信息所对应的订单明细状态为已完成
                            tFlag = tOrderDtlDAO.updateOrderDetailStatus(tUpdateOrderDtlBean, aConn, GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                            if (!tFlag) {
                                GSLogWriter.error(this, "修改订单明细状态失败");
                                break;
                            }
                        }
                    }
                    if (stockslist.size() <= 0 && tOrderDetailList.size() <= 0) {
                        GSLogWriter.error(this, "根据结算数据未查到对应的明细信息");
                        throw new GSException("根据结算数据未查到对应的明细信息");
                    }
                    if (tFlag) {
                        // 新增应收数据到应收应付信息表
                        for (int m = 0; m < aList.size(); m++) {
                            aVO = (GSBalanceManagePayRecvSaveVO) aList.get(m);
                            GSPayReceiveAbleBean tPayRecvAbleBean = new GSPayReceiveAbleBean();
                            tPayRecvAbleBean.setGs_workcorp_id(aVO.orgId);
                            tPayRecvAbleBean.setGs_workcorp_category(aVO.orgCategory);
                            tPayRecvAbleBean.setGs_balance_month(aVO.balancYM);
                            tPayRecvAbleBean.setGs_notes(aVO.notes);
                            // tPayRecvAbleBean.setGs_workcorp_level(aVO.orgLevel);
                            // tPayRecvAbleBean.setGs_workcorp_id_group(aVO.subOrgId);
                            tPayRecvAbleBean.setGs_fee_type_id(aVO.costType);
                            tPayRecvAbleBean.setGs_pay_date(aVO.recvDate);
                            tPayRecvAbleBean.setGs_pay_type(aVO.payType);
                            tPayRecvAbleBean.setGs_balance_need(aVO.balSum);
                            tPayRecvAbleBean.setGs_balance_undone(aVO.balSum);
                            tPayRecvAbleBean.setGs_pay_status(GSBaseConstants.UNPAY);
                            tPayRecvAbleBean.setGs_principal(aVO.principal);
                            tPayRecvAbleBean.setGs_operator_id(aOperBean.getGs_oper_id());
                            String tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                            tPayRecvAbleBean.setGs_operator_date(tCurDT);
                            tPayRecvAbleBean.setGs_offset_date(tCurDT);
                            tPayRecvAbleBean.setGs_receiveable_id(GenRandNum.genDTRandNum());
                            tFlag = tPayRecvDAO.insertPayReceiveInfo(tPayRecvAbleBean, aConn);
                            if (!tFlag) {
                                GSLogWriter.error(this, "新增应付信息到应收应付表失败");
                                break;
                            }
                        }
                        if (tFlag) {
                            GSLogWriter.info(this, "应付操作成功完成");
                        }
                    }
                } else {
                    GSLogWriter.error(this, "供应商结算信息状态修改失败");
                }
            } else {
                GSLogWriter.error(this, GSException.E40005_MSG);
                throw new GSException(GSException.E40005, GSException.E40005_MSG);
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            throw new GSException(GSException.E00001, GSException.E00001_MSG);
        }
        return tFlag;
    }

    /**
     * 进入生成应付页面
     * 
     * @param aVO
     * @return
     * @throws GSException
     */
    public HashMap productPayInfo(GSBalanceManagePayReceiveVO aVO) throws GSException {
        HashMap tMap = new HashMap();

        GSBargainDAO tBargDAO = new GSBargainDAO();
        try {
            // 查询合同信息
            ArrayList tList = tBargDAO.queryBargainByCustom(aVO.deptCategory, aVO.deptId);
            ArrayList tBargainList = new ArrayList();
            if (tList.size() > 0) {
                String[] tStr = null;
                String tBgnSerial = "";
                String tBgnId = "";
                String tBgnType = "";
                String tBgnCont = "";
                String tBgcCont = "";
                for (int i = 0; i < tList.size(); i++) {
                    GSBargainAndChargeVO tVO = (GSBargainAndChargeVO) tList.get(i);
                    tBgnId = tVO.bgnId;
                    tBgnSerial = tVO.bgnSerial;
                    tBgnType = tVO.bgnType;
                    tBgnCont = tVO.bgnContent;
                    ArrayList tChargeList = tBargDAO.queryBargainCharge(tBgnSerial);
                    if (tChargeList.size() > 0) {
                        for (int j = 0; j < tChargeList.size(); j++) {
                            GSBargainChargeBean tChargeBean = (GSBargainChargeBean) tChargeList.get(j);
                            if (j == 0) {
                                tBgcCont = tChargeBean.getGs_bgc_type() + ":" + tChargeBean.getGs_bgc_content();
                            } else {
                                tBgcCont = tBgcCont + ";" + tChargeBean.getGs_bgc_type() + ":" + tChargeBean.getGs_bgc_content();
                            }
                        }
                    }
                    if (i == tList.size() - 1) {
                        tStr = new String[5];
                        tStr[0] = tBgnId;
                        tStr[1] = tBgnSerial;
                        tStr[2] = tBgnType;
                        tStr[3] = tBgnCont;
                        tStr[4] = tBgcCont;
                        tBargainList.add(tStr);
                    } else if (i < tList.size() - 1 && i > 0) {
                        GSBargainAndChargeVO tVO2 = (GSBargainAndChargeVO) tList.get(i + 1);
                        if (tVO2 != null && !tVO2.bgnSerial.equals(tBgnSerial)) {
                            tStr = new String[5];
                            tStr[0] = tBgnId;
                            tStr[1] = tBgnSerial;
                            tStr[2] = tBgnType;
                            tStr[3] = tBgnCont;
                            tStr[4] = tBgcCont;
                            tBargainList.add(tStr);
                            tBgcCont = "";
                        }
                    }
                }
                // 将合同信息放入HASHMAP中
                tMap.put("bargain", tBargainList);
            }
            // 查询费用类型
            GSBalanceFeeDAO tBalFeeDAO = new GSBalanceFeeDAO();
            ArrayList tBalFeeList = tBalFeeDAO.queryAllFeeType();
            tMap.put("feetype", tBalFeeList);

            GSProviderDAO tProvDAO = new GSProviderDAO();

            String tOrgName = tProvDAO.queryProvider(aVO.deptId).getGs_provider_name();
            tMap.put("org", aVO.deptId);
            tMap.put("orgname", tOrgName);
            tMap.put("balanceym", aVO.balanceYM);
            tMap.put("deptcategory", aVO.deptCategory);
            tMap.put("balancsum", StringUtils.formatEDouble(aVO.balanceSum, 4));
            // 查询收款日期
            GSBargainDAO tBargainDAO = new GSBargainDAO();
            String tWeek = tBargainDAO.queryMaxBgnWeek(aVO.deptId, aVO.deptCategory);
            if (tWeek.equals("")) {
                tWeek = "60";
            }
            String tRecDate = DateUtil.getNextUpDay(Integer.parseInt(tWeek));
            tMap.put("recvday", DateUtil.formateDateTime(tRecDate));
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        }

        return tMap;
    }

    /**
     * 订单明细暂不结算
     * 
     * @param aVO
     * @param aOperBean
     * @return
     * @throws GSException
     */
    public boolean tempUnBalance(GSUnBalanceDetailOptVO aVO, GSOperatorBean aOperBean) throws GSException {
        boolean tFlag = false;
        Connection tConn = null;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        try {
            tConn = tBalMsgDAO.getConnetion();
            tConn.setAutoCommit(false);

            GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
            GSManufactureDAO tMDAO = new GSManufactureDAO();
            String CCZXID = GSSystemConfigurator.getParam("gs.provider.cczxid");
            ArrayList tList = aVO.orderDetailIds;
            BigDecimal subReduceAmt = new BigDecimal("0");
            String tProvider = "";

            // HashMap mapOrga = new HashMap();// 需要减去金额的订货单位列表
            HashMap mapProv = new HashMap();// 需要减去金额的供应商列表
            for (int i = 0; i < tList.size(); i++) {
                String tOrderDtlId = (String) tList.get(i);
                GSOrderDetailBean tOrdDtlBean = tOrderDtlDAO.queryOrderDetailByDetailId(tOrderDtlId);
                if (tOrdDtlBean != null) {
                    GSManufactureBean tMBean = tMDAO.getManufacture(tOrdDtlBean.getGs_manufacture_id());
                    subReduceAmt = new BigDecimal(tOrdDtlBean.getGs_signin_count()).multiply(new BigDecimal(tOrdDtlBean.getGs_goods_unitprice()));
                    tProvider = "0".equals(tMBean.getGs_is_tradeflat_manufacture()) ? CCZXID : tOrdDtlBean.getGs_provider_id();

                    if (mapProv.containsKey(tProvider)) {
                        BigDecimal temp = (BigDecimal) mapProv.get(tProvider);
                        temp = subReduceAmt.add(temp);
                        mapProv.put(tProvider, temp);
                    } else {
                        mapProv.put(tProvider, subReduceAmt);
                    }

                    // 修改订单明细状态
                    tOrdDtlBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS); // 修改订单明细为未纳入结算数据
                    tOrdDtlBean.setGs_is_prov_balanced(GSBaseConstants.UNBALANCE_STATUS);// 修改订单明细为未纳入订货单位结算数据
                    tOrdDtlBean.setGs_balance_month(null);
                    tOrdDtlBean.setGs_balance_month_provider(null);
                    tOrdDtlBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
                    tOrdDtlBean.setGs_lastmodify_contents("暂不结算");
                    tOrdDtlBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss"));
                    tFlag = tOrderDtlDAO.updateOrderDetailStatus(tOrdDtlBean, tConn, GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                    if (!tFlag) {
                        GSLogWriter.error(this, "修改订单明细未纳入结算数据失败");
                        throw new GSException("修改订单明细未纳入结算数据失败");
                    }
                } else {
                    GSLogWriter.error(this, "根据结算数据未查到对应的订单明细信息");
                    throw new GSException("根据结算数据未查到对应的订单明细信息");
                }
            }
            if (tFlag) {
                DecimalFormat tDecFmt = new DecimalFormat("###############.####");
                // 供应商结算数据
                Iterator it2 = mapProv.keySet().iterator();
                while (it2.hasNext()) {
                    double totalAmt2 = 0;
                    String provId = (String) it2.next();
                    BigDecimal temp = (BigDecimal) mapProv.get(provId);
                    ArrayList tBalList = tBalMsgDAO.queryBalanceInfoByOrderDept(provId, aVO.balanceYM, GSBaseConstants.UNBALANCE_STATUS);
                    if (tBalList.size() == 1) {
                        GSBalanceMsgBean tBalMsgBean2 = (GSBalanceMsgBean) tBalList.get(0);
                        totalAmt2 = Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
                        double subTotalAmt2 = Double.parseDouble(tDecFmt.format(temp.doubleValue()));
                        if (totalAmt2 > subTotalAmt2) {// 如果结算表中总金额大于要减去的金额则修改结算表数据
                            String[] tStr = new String[2];
                            tStr[0] = provId;
                            tStr[1] = String.valueOf(0 - subTotalAmt2);
                            tFlag = tBalMsgDAO.updateBalanceSum(tConn, tStr, aVO.balanceYM, aOperBean.getGs_oper_id());
                        } else {// 否则删除该笔结算数据
                            tFlag = tBalMsgDAO.abolishBalanceMsg(tConn, provId, aVO.balanceYM);
                        }
                        if (!tFlag) {
                            GSLogWriter.error("暂不结算操作修改供应商的结算表数据失败");
                            throw new GSException("暂不结算操作修改供应商的结算表数据失败");
                        }
                    } else {
                        GSLogWriter.error(this, GSException.E40010_MSG);
                        throw new GSException(GSException.E40010, GSException.E40010_MSG);
                    }
                }
                if (tFlag) {
                    GSLogWriter.info("暂不结算操作执行成功");
                    tConn.commit();
                }
            } else {
                GSLogWriter.info("暂不结算操作在修改订单明细时失败");
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw new GSException(GSException.E00001_MSG);
        } finally {
            if (tConn != null) {
                try {
                    tConn.setAutoCommit(true);
                    GSBaseDAO.close(tConn);
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
        }
        return tFlag;
    }

    /*
     * public boolean tempUnBalance(GSUnBalanceDetailOptVO aVO ,GSOperatorBean
     * aOperBean) throws GSException{ boolean tFlag = false; Connection tConn =
     * null; GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO(); try{ tConn =
     * tBalMsgDAO.getConnetion(); tConn.setAutoCommit(false);
     * 
     * GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO(); GSOrderDAO
     * tOrderDAO = new GSOrderDAO(); ArrayList tList = aVO.orderDetailIds;
     * ArrayList tProviderList = new ArrayList(); ArrayList tOrgList = new
     * ArrayList(); double totReduceAmt = 0; double subReduceAmt = 0; String
     * tProvider = ""; String tProviderBalYM = ""; String tOrg = ""; for(int
     * i=0; i<tList.size();i++){ String tOrderDtlId = (String)tList.get(i);
     * GSOrderDetailBean tOrdDtlBean =
     * tOrderDtlDAO.queryOrderDetailByDetailId(tOrderDtlId); if(tOrdDtlBean !=
     * null){
     * if(aVO.deptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
     * //取得订货单位所有订单关联的各供应商的结算金额
     * if(!tProvider.equals(tOrdDtlBean.getGs_provider_id())){
     * if(!tProvider.equals("")){ String[] tStr = new String[3]; tStr[0] =
     * tProvider; tStr[1] = String.valueOf(subReduceAmt); tStr[2] =
     * tProviderBalYM; tProviderList.add(tStr); } tProvider =
     * tOrdDtlBean.getGs_provider_id(); tProviderBalYM =
     * tOrdDtlBean.getGs_balance_month_provider(); subReduceAmt =
     * tOrdDtlBean.getGs_signin_count() * tOrdDtlBean.getGs_goods_unitprice();
     * 
     * }else{ subReduceAmt = subReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice(); } if(i == tList.size() - 1){
     * String[] tStr = new String[3]; tStr[0] = tProvider; tStr[1] =
     * String.valueOf(subReduceAmt); tStr[2] = tProviderBalYM;
     * tProviderList.add(tStr); } }else
     * if(aVO.deptCategory.equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)){
     * //取得供应商所有订单关联的各订货单位的结算金额 GSOrderBean tOrderBean =
     * tOrderDAO.queryOrder(tOrdDtlBean.getGs_order_temp_id());
     * if(!tOrg.equals(tOrderBean.getGs_workcorp_id())){ if(!tOrg.equals("")){
     * String[] tStr = new String[2]; tStr[0] = tOrg; tStr[1] =
     * String.valueOf(subReduceAmt); tOrgList.add(tStr); } tOrg =
     * tOrderBean.getGs_workcorp_id(); subReduceAmt =
     * tOrdDtlBean.getGs_signin_count() * tOrdDtlBean.getGs_goods_unitprice();
     * }else{ subReduceAmt = subReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice(); } if(i == tList.size() - 1){
     * String[] tStr = new String[2]; tStr[0] = tOrg; tStr[1] =
     * String.valueOf(subReduceAmt); tOrgList.add(tStr); } } //总的待减金额
     * totReduceAmt = totReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice(); //修改订单明细状态
     * tOrdDtlBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS);
     * //修改订单明细为未纳入结算数据
     * tOrdDtlBean.setGs_is_prov_balanced(GSBaseConstants.UNBALANCE_STATUS);//修改订单明细为未纳入订货单位结算数据
     * tOrdDtlBean.setGs_balance_month(null);
     * tOrdDtlBean.setGs_balance_month_provider(null);
     * tOrdDtlBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
     * tOrdDtlBean.setGs_lastmodify_contents("暂不结算");
     * tOrdDtlBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd
     * hh:mm:ss")); tFlag =
     * tOrderDtlDAO.updateOrderDetailStatus(tOrdDtlBean,tConn,GSBaseConstants.ORDER_DELIVERY_CONFIRM);
     * if(!tFlag){ GSLogWriter.error(this,"修改订单明细未纳入结算数据失败"); tConn.rollback();
     * break; } }else{ GSLogWriter.error(this,"根据结算数据未查到对应的订单明细信息"); throw new
     * GSException("根据结算数据未查到对应的订单明细信息"); } } if(tFlag){ ArrayList tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(aVO.deptId,aVO.balanceYM,GSBaseConstants.UNBALANCE_STATUS);
     * DecimalFormat tDecFmt = new DecimalFormat("###############.####");
     * if(tBalList.size() == 1){ //减去该单位在指定结算月份的选定的暂不结算明细的总金额 GSBalanceMsgBean
     * tBalMsgBean = (GSBalanceMsgBean)tBalList.get(0); double totalAmt =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean.getGs_balance_sum()));
     * totReduceAmt = Double.parseDouble(tDecFmt.format(totReduceAmt));
     * if(totalAmt > totReduceAmt){ String[] tStr = new String[2]; tStr[0] =
     * aVO.deptId; tStr[1] = String.valueOf(totalAmt - totReduceAmt); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,aVO.balanceYM,aOperBean.getGs_oper_id());
     * }else { tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,aVO.deptId,aVO.balanceYM); }
     * if(!tFlag){ GSLogWriter.error("暂不结算操作修改结算表数据失败"); tConn.rollback(); }else {
     * 
     * if(tOrgList.size() > 0){//修改相关订货单位的结算金额 double totalAmt2 = 0; for(int
     * j=0; j<tOrgList.size();j++){ String temp[] = (String[])tOrgList.get(j);
     * tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(temp[0],aVO.balanceYM,GSBaseConstants.UNBALANCE_STATUS);
     * if(tBalList.size() == 1){ GSBalanceMsgBean tBalMsgBean2 =
     * (GSBalanceMsgBean)tBalList.get(0); totalAmt2 =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
     * double subTotalAmt2 =
     * Double.parseDouble(tDecFmt.format(Double.parseDouble(temp[1])));
     * if(totalAmt2 > subTotalAmt2){//如果结算表中总金额大于要减去的金额则修改结算表数据 String[] tStr =
     * new String[2]; tStr[0] = tBalMsgBean2.getGs_workcorp_id(); tStr[1] =
     * String.valueOf(totalAmt2 - subTotalAmt2); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,aVO.balanceYM,aOperBean.getGs_oper_id());
     * }else{//否则删除该笔结算数据 tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,temp[0],aVO.balanceYM); } if(!tFlag){
     * GSLogWriter.error("暂不结算操作修改订货单位的结算表数据失败"); tConn.rollback(); break; }
     * }else{ GSLogWriter.error(this,GSException.E40005_MSG); throw new
     * GSException(GSException.E40005,GSException.E40005_MSG); } } }else
     * if(tProviderList.size() > 0){//修改相关供应商的结算金额 double totalAmt2 = 0; for(int
     * j=0; j<tProviderList.size();j++){ String temp[] =
     * (String[])tProviderList.get(j); tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(temp[0],temp[2],GSBaseConstants.UNBALANCE_STATUS);
     * if(tBalList.size() == 1){ GSBalanceMsgBean tBalMsgBean2 =
     * (GSBalanceMsgBean)tBalList.get(0); totalAmt2 =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
     * double subTotalAmt2 =
     * Double.parseDouble(tDecFmt.format(Double.parseDouble(temp[1])));
     * if(totalAmt2 > subTotalAmt2){//如果结算表中总金额大于要减去的金额则修改结算表数据 String[] tStr =
     * new String[2]; tStr[0] = tBalMsgBean2.getGs_workcorp_id(); tStr[1] =
     * String.valueOf(totalAmt2 - subTotalAmt2); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,temp[2],aOperBean.getGs_oper_id());
     * }else{//否则删除该笔结算数据 tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,temp[0],temp[2]); } if(!tFlag){
     * GSLogWriter.error("暂不结算操作修改供应商的结算表数据失败"); tConn.rollback(); break; }
     * }else{ GSLogWriter.error(this,GSException.E40010_MSG); throw new
     * GSException(GSException.E40010,GSException.E40010_MSG); } } } if(tFlag){
     * GSLogWriter.info("暂不结算操作执行成功"); tConn.commit(); } } }else{
     * GSLogWriter.error(this,GSException.E40005_MSG); throw new
     * GSException(GSException.E40005,GSException.E40005_MSG); } }else{
     * GSLogWriter.info("暂不结算操作在修改订单明细时失败"); } }catch(GSException ge){ if(tConn !=
     * null){ try{ tConn.rollback(); }catch(SQLException se){
     * se.printStackTrace(); } } throw ge; }catch(Exception e){ if(tConn !=
     * null){ try{ tConn.rollback(); }catch(SQLException se){
     * se.printStackTrace(); } } throw new GSException(GSException.E00001_MSG);
     * }finally{ if(tConn != null){ try{ tConn.setAutoCommit(true);
     * tConn.close(); }catch(SQLException se){ se.printStackTrace(); } } }
     * return tFlag; }
     */
    /**
     * 订单明细结算作废
     * 
     * @param aVO
     * @param aOperBean
     *            操作员编码
     * @return
     * @throws GSException
     */
    public boolean abolishUnBalance(GSUnBalanceDetailOptVO aVO, String abolishCause, GSOperatorBean aOperBean) throws GSException {
        boolean tFlag = false;
        Connection tConn = null;
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        try {
            tConn = tBalMsgDAO.getConnetion();
            tConn.setAutoCommit(false);

            GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
            GSManufactureDAO tMDAO = new GSManufactureDAO();
            String CCZXID = GSSystemConfigurator.getParam("gs.provider.cczxid");
            ArrayList tList = aVO.orderDetailIds;
            ArrayList tList2 = aVO.manustate;
            BigDecimal subReduceAmt = new BigDecimal("0");
            String tProvider = "";
            String tOrg = "";
            HashMap mapProv = new HashMap();// 需要减去金额的供应商列表
            ArrayList tSubmitList = new ArrayList();// 待向交易平台通知作废的明细列表
            for (int i = 0; i < tList.size(); i++) {
                String tOrderDtlId = (String) tList.get(i);
                GSOrderDetailBean tOrdDtlBean = tOrderDtlDAO.queryOrderDetailByDetailId(tOrderDtlId);
                if (tOrdDtlBean != null) {

                    GSManufactureBean tMBean = tMDAO.getManufacture(tOrdDtlBean.getGs_manufacture_id());
                    subReduceAmt = new BigDecimal(tOrdDtlBean.getGs_signin_count()).multiply(new BigDecimal(tOrdDtlBean.getGs_goods_unitprice()));
                    tProvider = "0".equals(tMBean.getGs_is_tradeflat_manufacture()) ? CCZXID : tOrdDtlBean.getGs_provider_id();
                    if (mapProv.containsKey(tProvider)) {
                        BigDecimal temp = (BigDecimal) mapProv.get(tProvider);
                        temp = subReduceAmt.add(temp);
                        mapProv.put(tProvider, temp);
                    } else {
                        mapProv.put(tProvider, subReduceAmt);
                    }

                    // 修改该笔订单明细
                    tOrdDtlBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS); // 修改订单明细为未纳入结算数据
                    tOrdDtlBean.setGs_is_prov_balanced(GSBaseConstants.UNBALANCE_STATUS); // 修改订单明细为未纳入结算数据
                    tOrdDtlBean.setGs_order_detail_status(GSBaseConstants.ORDER_BLANK_OUT); // 修改订单明细状态为作废
                    tOrdDtlBean.setGs_balance_month(null);
                    tOrdDtlBean.setGs_balance_month_provider(null);
                    tOrdDtlBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
                    tOrdDtlBean.setGs_lastmodify_contents("订单作废");
                    String tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                    tOrdDtlBean.setGs_lastmodify_date(tCurDT);
                    tOrdDtlBean.setGs_cancel_cause(abolishCause); // 取消原因
                    tOrdDtlBean.setGs_cancel_date(tCurDT);
                    tOrdDtlBean.setGs_cancel_person(aOperBean.getGs_oper_id());
                    tSubmitList.add(tOrdDtlBean);
                    tFlag = tOrderDtlDAO.updateOrderDetailStatus(tOrdDtlBean, tConn, GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                    if (!tFlag) {
                        GSLogWriter.error(this, "修改订单明细未纳入结算数据失败");
                        tConn.rollback();
                        break;
                    }
                } else {
                    GSLogWriter.error(this, "根据结算数据未查到对应的订单明细信息");
                    throw new GSException("根据结算数据未查到对应的订单明细信息");
                }
            }

            if (tFlag) {
                DecimalFormat tDecFmt = new DecimalFormat("###############.####");
                Iterator it2 = mapProv.keySet().iterator();
                while (it2.hasNext()) {
                    double totalAmt2 = 0;
                    String provId = (String) it2.next();
                    BigDecimal temp = (BigDecimal) mapProv.get(provId);
                    ArrayList tBalList = tBalMsgDAO.queryBalanceInfoByOrderDept(provId, aVO.balanceYM, GSBaseConstants.UNBALANCE_STATUS);
                    if (tBalList.size() == 1) {
                        GSBalanceMsgBean tBalMsgBean2 = (GSBalanceMsgBean) tBalList.get(0);
                        totalAmt2 = Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
                        double subTotalAmt2 = Double.parseDouble(tDecFmt.format(temp.doubleValue()));
                        if (totalAmt2 > subTotalAmt2) {// 如果结算表中总金额大于要减去的金额则修改结算表数据
                            String[] tStr = new String[2];
                            tStr[0] = provId;
                            tStr[1] = String.valueOf(0 - subTotalAmt2);
                            tFlag = tBalMsgDAO.updateBalanceSum(tConn, tStr, aVO.balanceYM, aOperBean.getGs_oper_id());
                        } else {// 否则删除该笔结算数据
                            tFlag = tBalMsgDAO.abolishBalanceMsg(tConn, provId, aVO.balanceYM);
                        }
                        if (!tFlag) {
                            GSLogWriter.error("暂不结算操作修改供应商的结算表数据失败");
                            tConn.rollback();
                            break;
                        }
                    } else {
                        GSLogWriter.error(this, GSException.E40010_MSG);
                        throw new GSException(GSException.E40010, GSException.E40010_MSG);
                    }
                }

                if (tFlag) {
                    for (int i = 0; i < tList2.size(); i++) {
                        String sta = (String) tList2.get(i);
                        if ("2".equals(sta)) {
                            tConn.commit();
                            GSLogWriter.info(this, "非网上产品，不用向交易平台提交");
                        } else {
                            // 通知交易平台
                            String tRs = this.submitAbolishDetailToApep(tSubmitList);
                            if (tRs.equals("1")) {
                                tConn.commit();
                                GSLogWriter.info(this, "订单明细作废修改明细状态并向交易平台发送信息成功");
                            } else {
                                GSLogWriter.error(this, "向交易平台发送订单明细作废信息失败");
                                throw new GSException("向交易平台发送订单明细作废信息失败");
                            }
                        }
                    }
                } else {
                    GSLogWriter.error(this, GSException.E40005_MSG);
                    throw new GSException(GSException.E40005, GSException.E40005_MSG);
                }

            } else {
                throw new GSException(GSException.E40011, GSException.E40011_MSG);
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw new GSException(GSException.E00001_MSG);
        } finally {
            if (tConn != null) {
                try {
                    tConn.setAutoCommit(true);
                    GSBaseDAO.close(tConn);
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
        }
        return tFlag;
    }

    /*
     * public boolean abolishUnBalance(GSUnBalanceDetailOptVO aVO
     * ,GSOperatorBean aOperBean) throws GSException{ boolean tFlag = false;
     * Connection tConn = null; GSBalanceMsgDAO tBalMsgDAO = new
     * GSBalanceMsgDAO(); try{ tConn = tBalMsgDAO.getConnetion();
     * tConn.setAutoCommit(false);
     * 
     * GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO(); GSOrderDAO
     * tOrderDAO = new GSOrderDAO(); ArrayList tList = aVO.orderDetailIds;
     * ArrayList tProviderList = new ArrayList(); ArrayList tOrgList = new
     * ArrayList(); double totReduceAmt = 0; double subReduceAmt = 0; String
     * tProvider = ""; String tProviderBalYM= ""; String tOrg = ""; ArrayList
     * tSubmitList = new ArrayList();//待向交易平台通知作废的明细列表 for(int i=0; i<tList.size();i++){
     * String tOrderDtlId = (String)tList.get(i); GSOrderDetailBean tOrdDtlBean =
     * tOrderDtlDAO.queryOrderDetailByDetailId(tOrderDtlId); if(tOrdDtlBean !=
     * null){ //取得订货单位所有订单关联的各供应商的结算金额
     * if(aVO.deptCategory.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
     * if(!tProvider.equals(tOrdDtlBean.getGs_provider_id())){
     * if(!tProvider.equals("")){ String[] tStr = new String[3]; tStr[0] =
     * tProvider; tStr[1] = String.valueOf(subReduceAmt); tStr[2] =
     * tProviderBalYM; tProviderList.add(tStr); } tProvider =
     * tOrdDtlBean.getGs_provider_id(); subReduceAmt =
     * tOrdDtlBean.getGs_signin_count() * tOrdDtlBean.getGs_goods_unitprice();
     * tProviderBalYM = tOrdDtlBean.getGs_balance_month_provider();
     * 
     * }else{ subReduceAmt = subReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice(); } if(i == tList.size() - 1){
     * String[] tStr = new String[3]; tStr[0] = tProvider; tStr[1] =
     * String.valueOf(subReduceAmt); tStr[2] = tProviderBalYM;
     * tProviderList.add(tStr); } }else
     * if(aVO.deptCategory.equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)){
     * //取得供应商所有订单关联的各订货单位的结算金额 GSOrderBean tOrderBean =
     * tOrderDAO.queryOrder(tOrdDtlBean.getGs_order_temp_id());
     * if(!tOrg.equals(tOrderBean.getGs_workcorp_id())){ if(!tOrg.equals("")){
     * String[] tStr = new String[2]; tStr[0] = tOrg; tStr[1] =
     * String.valueOf(subReduceAmt); tOrgList.add(tStr); } tOrg =
     * tOrderBean.getGs_workcorp_id(); subReduceAmt =
     * tOrdDtlBean.getGs_signin_count() * tOrdDtlBean.getGs_goods_unitprice();
     * }else{ subReduceAmt = subReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice(); } if(i == tList.size() - 1){
     * String[] tStr = new String[2]; tStr[0] = tOrg; tStr[1] =
     * String.valueOf(subReduceAmt); tOrgList.add(tStr); } } //修改该笔订单明细
     * totReduceAmt = totReduceAmt + tOrdDtlBean.getGs_signin_count() *
     * tOrdDtlBean.getGs_goods_unitprice();
     * tOrdDtlBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS);
     * //修改订单明细为未纳入结算数据
     * tOrdDtlBean.setGs_order_detail_status(GSBaseConstants.ORDER_BLANK_OUT);
     * //修改订单明细状态为作废 tOrdDtlBean.setGs_balance_month(null);
     * tOrdDtlBean.setGs_balance_month_provider(null);
     * tOrdDtlBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
     * tOrdDtlBean.setGs_lastmodify_contents("订单作废"); String tCurDT =
     * DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
     * tOrdDtlBean.setGs_lastmodify_date(tCurDT);
     * tOrdDtlBean.setGs_cancel_cause("结算订单作废"); //取消原因
     * tOrdDtlBean.setGs_cancel_date(tCurDT);
     * tOrdDtlBean.setGs_cancel_person(aOperBean.getGs_oper_id());
     * tSubmitList.add(tOrdDtlBean); tFlag =
     * tOrderDtlDAO.updateOrderDetailStatus(tOrdDtlBean,tConn,GSBaseConstants.ORDER_DELIVERY_CONFIRM);
     * if(!tFlag){ GSLogWriter.error(this,"修改订单明细未纳入结算数据失败"); tConn.rollback();
     * break; } }else{ GSLogWriter.error(this,"根据结算数据未查到对应的订单明细信息"); throw new
     * GSException("根据结算数据未查到对应的订单明细信息"); } } if(tFlag){ ArrayList tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(aVO.deptId,aVO.balanceYM,GSBaseConstants.UNBALANCE_STATUS);
     * if(tBalList.size() == 1){ //减去该单位在指定结算月份的选定的暂不结算明细的总金额 GSBalanceMsgBean
     * tBalMsgBean = (GSBalanceMsgBean)tBalList.get(0);
     * 
     * DecimalFormat tDecFmt = new DecimalFormat("###############.####"); double
     * totalAmt =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean.getGs_balance_sum()));
     * totReduceAmt = Double.parseDouble(tDecFmt.format(totReduceAmt));
     * if(totalAmt > totReduceAmt){ String[] tStr = new String[2]; tStr[0] =
     * aVO.deptId; tStr[1] = String.valueOf(totalAmt - totReduceAmt); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,aVO.balanceYM,aOperBean.getGs_oper_id());
     * }else { tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,aVO.deptId,aVO.balanceYM); }
     * if(!tFlag){ GSLogWriter.error("作废操作修改结算表数据失败"); tConn.rollback(); }else {
     * if(tOrgList.size() > 0){//修改相关订货单位的结算金额 double totalAmt2 = 0; for(int
     * j=0; j<tOrgList.size();j++){ String temp[] = (String[])tOrgList.get(j);
     * tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(temp[0],aVO.balanceYM,GSBaseConstants.UNBALANCE_STATUS);
     * 
     * if(tBalList.size() == 1){ GSBalanceMsgBean tBalMsgBean2 =
     * (GSBalanceMsgBean)tBalList.get(0); // totalAmt2 =
     * tBalMsgBean2.getGs_balance_sum(); totalAmt2 =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
     * double subTotalAmt2 =
     * Double.parseDouble(tDecFmt.format(Double.parseDouble(temp[1])));
     * if(totalAmt2 > subTotalAmt2){//如果结算表中总金额大于要减去的金额则修改结算表数据 String[] tStr =
     * new String[2]; tStr[0] = tBalMsgBean2.getGs_workcorp_id(); tStr[1] =
     * String.valueOf(totalAmt2 - subTotalAmt2); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,aVO.balanceYM,aOperBean.getGs_oper_id());
     * }else{//否则删除该笔结算数据 tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,temp[0],aVO.balanceYM); } if(!tFlag){
     * GSLogWriter.error("作废操作修改订货单位的结算表数据失败"); tConn.rollback(); break; }
     * }else{ GSLogWriter.error(this,GSException.E40005_MSG); throw new
     * GSException(GSException.E40005,GSException.E40005_MSG); } } }else
     * if(tProviderList.size() > 0){//修改相关供应商的结算金额 double totalAmt2 = 0; for(int
     * j=0; j<tProviderList.size();j++){ String temp[] =
     * (String[])tProviderList.get(j); tBalList =
     * tBalMsgDAO.queryBalanceInfoByOrderDept(temp[0],aVO.balanceYM,GSBaseConstants.UNBALANCE_STATUS);
     * 
     * if(tBalList.size() == 1){ GSBalanceMsgBean tBalMsgBean2 =
     * (GSBalanceMsgBean)tBalList.get(0); // totalAmt2 =
     * tBalMsgBean2.getGs_balance_sum(); totalAmt2 =
     * Double.parseDouble(tDecFmt.format(tBalMsgBean2.getGs_balance_sum()));
     * double subTotalAmt2 =
     * Double.parseDouble(tDecFmt.format(Double.parseDouble(temp[1])));
     * if(totalAmt2 > subTotalAmt2){//如果结算表中总金额大于要减去的金额则修改结算表数据 String[] tStr =
     * new String[2]; tStr[0] = tBalMsgBean2.getGs_workcorp_id(); tStr[1] =
     * String.valueOf(totalAmt2 - subTotalAmt2); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tStr,aVO.balanceYM,aOperBean.getGs_oper_id());
     * }else{//否则删除该笔结算数据 tFlag =
     * tBalMsgDAO.abolishBalanceMsg(tConn,temp[0],aVO.balanceYM); } if(!tFlag){
     * GSLogWriter.error("作废操作修改供应商的结算表数据失败"); tConn.rollback(); break; } }else{
     * GSLogWriter.error(this,GSException.E40005_MSG); throw new
     * GSException(GSException.E40005,GSException.E40005_MSG); } } } if(tFlag){
     * //通知交易平台 String tRs = this.submitAbolishDetailToApep(tSubmitList);
     * if(tRs.equals("1")){ tConn.commit();
     * GSLogWriter.info(this,"订单明细作废修改明细状态并向交易平台发送信息成功"); }else{
     * GSLogWriter.error(this,"向交易平台发送订单明细作废信息失败"); throw new
     * GSException("向交易平台发送订单明细作废信息失败"); } } } }else{
     * GSLogWriter.error(this,GSException.E40005_MSG); throw new
     * GSException(GSException.E40005,GSException.E40005_MSG); } }else{ throw
     * new GSException (GSException.E40011,GSException.E40011_MSG); }
     * }catch(GSException ge){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se){ se.printStackTrace(); } } throw ge;
     * }catch(Exception e){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se){ se.printStackTrace(); } } throw new
     * GSException(GSException.E00001_MSG); }finally{ if(tConn != null){ try{
     * tConn.setAutoCommit(true); tConn.close(); }catch(SQLException se){
     * se.printStackTrace(); } } } return tFlag; }
     */
    /**
     * 向交易平台发送订单作废信息
     * 
     * @param tList
     * @return
     * @throws GSException
     */
    private String submitAbolishDetailToApep(ArrayList tList) throws GSException, Exception {
        String tRs = "";
        // 读取采购网给巴士物资的编码
        String tPurCode = GSSystemConfigurator.getParam("gs.purcode");
        // 组装信息
        // StringBuffer tSb = new StringBuffer("Action=BlankoutOrder&Count=" +
        // tList.size());

        ParameterFactory pf = new ParameterFactory();
        pf.addParam("Action", "BlankoutOrder");
        pf.addParam("Count", String.valueOf(tList.size()));

        for (int i = 0; i < tList.size(); i++) {
            GSOrderDetailBean tOrdDtlBean = (GSOrderDetailBean) tList.get(i);
            /*
             * tSb.append("&CusOrderItemCode_" + i +"=" +
             * tOrdDtlBean.getGs_order_detail_id());// 集中采购系统订单明细ID
             * tSb.append("&BlankoutReason_" + i + "=" +
             * tOrdDtlBean.getGs_cancel_cause());// 作废原因
             * tSb.append("&BlankoutTime_" + i + "=" +
             * tOrdDtlBean.getGs_cancel_date());// 作废日期和时间
             * tSb.append("&SubmitPerson_" + i + "=" +
             * tOrdDtlBean.getGs_cancel_person());// 作废操作人姓名
             * tSb.append("&CusCode_" + i + "=" + tPurCode);// 巴士物资编号 if(i ==
             * tList.size()-1){//结束符 tSb.append("&"); }
             */
            pf.addParam("CusOrderItemCode_" + i, tOrdDtlBean.getGs_order_detail_id());
            pf.addParam("BlankoutReason_" + i, tOrdDtlBean.getGs_cancel_cause());
            pf.addParam("BlankoutTime_" + i, tOrdDtlBean.getGs_cancel_date());
            GSOperatorDAO dao = new GSOperatorDAO();
            GSOperatorBean bean = dao.queryOperById(tOrdDtlBean.getGs_cancel_person());
            if (bean == null)
                bean = new GSOperatorBean();
            pf.addParam("SubmitPerson_" + i, bean.getGs_oper_name());
            pf.addParam("CusCode_" + i, tPurCode);

        }
        // GSLogWriter.debug(this, "传送内容" + tSb.toString());
        GSLogWriter.debug(this, "传送内容" + pf.getStrStream());
        // 取得配置文件中服务端IP和端口参数
        String tIP = GSSystemConfigurator.getParam("gs.ip");
        String tPort = GSSystemConfigurator.getParam("gs.port");
        // 连接服务端
        GSClientSocket tClientSocket = new GSClientSocket(tIP, Integer.parseInt(tPort));

        // 发送订单信息到采购网
        tRs = tClientSocket.sendContents(pf.getStrStream());

        return tRs;
    }

    public ArrayList getSignedOrderDetailOfDept(GSUnBalanceDetailQryVO aVO, int pageNo, int pageSize) throws GSException {
        ArrayList tList = new ArrayList();
        String tBalYM = aVO.balanceYM;
        String tEndDate = tBalYM;
        GSBalanceParamDAO tBalParamDAO = new GSBalanceParamDAO();
        GSBalanceParamBean tBalParamBean = tBalParamDAO.queryBalanceDate();
        // 取得结算截至日期
        if (tBalParamBean.getGs_balance_date_type().equals(GSBaseConstants.NATURE_BALANCE_DATE)) {
            Calendar tCal = Calendar.getInstance();
            tCal.set(Calendar.YEAR, Integer.parseInt(tBalYM.substring(0, 4)));
            tCal.set(Calendar.MONTH, Integer.parseInt(tBalYM.substring(4)) - 1);
            tEndDate = tEndDate + tCal.getActualMaximum(Calendar.DAY_OF_MONTH);
        } else if (tBalParamBean.getGs_balance_date_type().equals(GSBaseConstants.MANUAL_BALANCE_DATE)) {
            if (Integer.parseInt(tBalParamBean.getGs_balance_end_date()) < 10) {
                tEndDate = tEndDate + "0" + tBalParamBean.getGs_balance_end_date();
            } else {
                tEndDate = tEndDate + tBalParamBean.getGs_balance_end_date();
            }
        }
        aVO.endBalDate = tEndDate;
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        tList = tOrderDtlDAO.queryAddableSignedDetail(aVO, pageNo, pageSize);
        return tList;
    }

    /**
     * 新增订单到相关订货单位的结算数据中
     * 
     * @param aForm
     * @return
     * @throws GSException
     */

    public boolean addSignedOrderDetailToBalMsg(GSAddUnBalanceDetailForm aForm) throws GSException {
        boolean tFlag = false;
        // 取得当前操作员信息
        GSOperatorBean tOperBean = (GSOperatorBean) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        String index[] = aForm.getIndex();
        // 取得结算开始和截至日期
        String tDate[] = this.getBalDatePeriod(aForm.balYM);
        String tEndDate = tDate[1];
        tEndDate = tEndDate.substring(0, 4) + tEndDate.substring(5, 7) + tEndDate.substring(8, 10);
        String tEndDate1 = tEndDate.substring(0, 6);

        tFlag = doBalanceRecord(index, tEndDate1, tOperBean, tDate);

        return tFlag;
    }

    /*
     * 该方法被替换 public boolean
     * addSignedOrderDetailToBalMsg(GSAddUnBalanceDetailForm aForm) throws
     * GSException{ boolean tFlag = false; Connection tConn = null; try{
     * //取得当前操作员信息 GSOperatorBean tOperBean =
     * (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
     * 
     * String index[] = aForm.getIndex(); GSOrderDetailDAO tOrderDtlDAO = new
     * GSOrderDetailDAO(); GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
     * double totalAmt = 0; double providerTotalAmt = 0; tConn =
     * tOrderDtlDAO.getConnetion(); tConn.setAutoCommit(false); String
     * tProviderId = ""; GSBalanceInfoVO tBalInfoVO = null; String
     * tProviderBalYM = ""; String tempBalYM = ""; ArrayList tUpdateBalList =
     * new ArrayList(); ArrayList tBalanceList = new ArrayList(); //取得结算开始和截至日期
     * String tDate[] = this.getBalDatePeriod(aForm.balYM);
     * 
     * for(int i=0; i<index.length; i++){ String tOrderDetailId = index[i];
     * GSOrderDetailBean tOrderDtlBean =
     * tOrderDtlDAO.queryOrderDetailByDetailId(tOrderDetailId);
     * //累计订货单位新增结算明细总金额 totalAmt = totalAmt +
     * tOrderDtlBean.getGs_signin_count() *
     * tOrderDtlBean.getGs_goods_unitprice();
     * 
     * if(tProviderId.equals(tOrderDtlBean.getGs_provider_id())){
     * //累计供应商新增结算明细金额 providerTotalAmt = providerTotalAmt +
     * tOrderDtlBean.getGs_signin_count() *
     * tOrderDtlBean.getGs_goods_unitprice(); }else{ tempBalYM = "";
     * //分别针对不同供应商统计结算金额，并放入待插入结算表的集合中 if(!tProviderId.equals("")){
     * processProviderBalMsg(providerTotalAmt,tBalanceList,tUpdateBalList,tProviderId,aForm.balYM,tProviderBalYM,tBalInfoVO); }
     * tProviderBalYM = aForm.balYM; tBalInfoVO = new GSBalanceInfoVO();
     * tBalInfoVO.deptId = tOrderDtlBean.getGs_provider_id();
     * tBalInfoVO.deptType = GSBaseConstants.BALANCE_PROVIDER_TYPE;
     * tBalInfoVO.payType = GSBaseConstants.PAYMENT_TYPE; providerTotalAmt =
     * tOrderDtlBean.getGs_signin_count() *
     * tOrderDtlBean.getGs_goods_unitprice(); tProviderId =
     * tOrderDtlBean.getGs_provider_id(); }
     * if(tempBalYM.equals("")){//判断临时供应商结算月份值是否为空，若为空，则需赋值 tempBalYM =
     * getProviderBalanceYM(tProviderId,aForm.balYM); tProviderBalYM =
     * tempBalYM; } //处理最后一笔客户统计数据的情况 if(i == index.length - 1){
     * processProviderBalMsg(providerTotalAmt,tBalanceList,tUpdateBalList,tProviderId,aForm.balYM,tProviderBalYM,tBalInfoVO); }
     * //修改该笔订单明细为已纳入结算
     * tOrderDtlBean.setGs_is_balanced(GSBaseConstants.BALANCE_STATUS);
     * tOrderDtlBean.setGs_balance_month(aForm.balYM);
     * tOrderDtlBean.setGs_balance_month_provider(tProviderBalYM);
     * tOrderDtlBean.setGs_lastmodifer_id(tOperBean.getGs_oper_id());
     * tOrderDtlBean.setGs_lastmodify_contents("订单明细纳入结算");
     * tOrderDtlBean.setGs_lastmodify_date(DateUtil.getCurrentDate("yyyy-MM-dd
     * hh:mm:ss")); tFlag =
     * tOrderDtlDAO.updateDetailBalanced(tConn,tOrderDtlBean); if(!tFlag){
     * GSLogWriter.error(this,"修改订单明细为已结算状态失败"); throw new
     * GSException(GSException.E40006,GSException.E40006_MSG); } }
     * 
     * //判断该月份此订货单位是否存在结算信息 ArrayList tOrderDeptList =
     * tBalMsgDAO.queryBalanceInfo(aForm.deptId,aForm.balYM);
     * if(tOrderDeptList.size() == 1){ GSBalanceMsgBean tBalMsgBean =
     * (GSBalanceMsgBean)tOrderDeptList.get(0); String[] tDept = new String[2];
     * tDept[0] = aForm.deptId; tDept[1] =
     * String.valueOf(tBalMsgBean.getGs_balance_sum() + totalAmt); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tDept,aForm.balYM,tOperBean.getGs_oper_id());
     * if(!tFlag){ GSLogWriter.error(this,GSException.E40015_MSG); throw new
     * GSException(GSException.E40015,GSException.E40015_MSG); } }else{
     * tBalInfoVO = new GSBalanceInfoVO(); tBalInfoVO.deptId = aForm.deptId;
     * tBalInfoVO.totalAmt = totalAmt; tBalInfoVO.balanceYM = aForm.balYM;
     * tBalInfoVO.deptType = GSBaseConstants.BALANCE_ORDERDEPT_TYPE;
     * tBalInfoVO.payType = GSBaseConstants.RECEIVE_TYPE;
     * tBalanceList.add(tBalInfoVO); } //新增对帐数据 if(tBalanceList.size() > 0){
     * for(int i=0; i<tBalanceList.size(); i++){ GSBalanceInfoVO tVO =
     * (GSBalanceInfoVO)tBalanceList.get(i); tVO.startDate = tDate[0];
     * tVO.endDate = tDate[1]; tVO.operatorId = tOperBean.getGs_oper_id();
     * tVO.operateDate = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
     * tVO.balanceFlag = GSBaseConstants.UNBALANCE_STATUS; tFlag =
     * tBalMsgDAO.insertBalanceInfo(tVO,tConn); if(!tFlag){
     * GSLogWriter.error(this,"写结算信息表失败"); tConn.rollback(); break; } }
     * if(tFlag){ GSLogWriter.info(this,"成功写入新数据到结算信息表"); } } //修改供应商对帐数据
     * if(tFlag){ if(tUpdateBalList.size() > 0){ for(int i=0; i<tUpdateBalList.size();
     * i++){ String[] tBalMsg = (String[])tUpdateBalList.get(i); tFlag =
     * tBalMsgDAO.updateBalanceSum(tConn,tBalMsg,aForm.balYM,tOperBean.getGs_oper_id());
     * if(!tFlag){ GSLogWriter.error(this,"修改结算信息表中已存在供应商结算金额失败");
     * tConn.rollback(); break; } } if(tFlag){
     * GSLogWriter.info(this,"成功修改结算信息表中供应商结算金额"); } } }else{ throw new
     * GSException(GSException.E00001,GSException.E00001); }
     * if(tBalanceList.size() < 1 && tUpdateBalList.size() < 1){
     * GSLogWriter.error(this,"无可写入到结算信息表的数据，需检查数据或程序"); throw new
     * GSException("无可写入到结算信息表的数据，需检查数据或程序"); }else{ if(tFlag){
     * tConn.rollback(); GSLogWriter.info(this,"成功新增或修改结算信息表中供应商的结算金额"); } }
     * 
     * }catch(GSException ge){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se ){ se.printStackTrace(); } } throw ge;
     * }catch(Exception e){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se ){ se.printStackTrace(); } }
     * GSLogWriter.error(this,e.toString()); throw new
     * GSException(e.toString()); }finally{ if(tConn != null){ try{
     * tConn.setAutoCommit(true); tConn.close(); }catch(SQLException se){
     * se.printStackTrace(); } } } return tFlag; }
     */
    /**
     * 统计供应商的订单并计算其结算信息
     * 
     * @param aProviderTotalAmt
     *            结算总金额
     * @param aBalanceList
     *            需新增的结算信息
     * @param aUpdateBalList
     *            需修改的结算信息
     * @param aProviderId
     *            供应商编码
     * @param aBalYM
     *            结算月份
     * @return
     * @throws GSException
     */
    private void processProviderBalMsg(double aProviderTotalAmt, ArrayList aBalanceList, ArrayList aUpdateBalList, String aProviderId, String aBalYM,
            String aProviderBalYM, GSBalanceInfoVO aBalInfoVO) throws GSException {
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        // 查询该供应商在该月份是否有已结算的信息
        ArrayList temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(aProviderId, aBalYM, GSBaseConstants.BALANCE_STATUS);
        if (temp2.size() > 0) {
            temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(aProviderId, aProviderBalYM, GSBaseConstants.UNBALANCE_STATUS);
            if (temp2.size() == 1) {
                GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp2.get(0);
                aProviderTotalAmt = aProviderTotalAmt + tBalMsgBean.getGs_balance_sum();
                String[] tStr = new String[2];
                tStr[0] = tBalMsgBean.getGs_workcorp_id();
                tStr[1] = String.valueOf(aProviderTotalAmt);
                aUpdateBalList.add(tStr);
            } else {
                aBalInfoVO.totalAmt = aProviderTotalAmt;
                aBalInfoVO.balanceYM = aProviderBalYM;
                aBalInfoVO.actualBalanceDept = aProviderId;
                aBalanceList.add(aBalInfoVO);
            }
        } else {
            // 如果结算表中已存在该供应商在该月份的待结算金额，则累加,否则新增
            ArrayList temp = tBalMsgDAO.queryBalanceInfoByOrderDept(aProviderId, aBalYM, GSBaseConstants.UNBALANCE_STATUS);
            if (temp.size() > 0) {
                GSBalanceMsgBean tBalMsgBean = (GSBalanceMsgBean) temp.get(0);
                aProviderTotalAmt = aProviderTotalAmt + tBalMsgBean.getGs_balance_sum();
                String[] tStr = new String[2];
                tStr[0] = tBalMsgBean.getGs_workcorp_id();
                tStr[1] = String.valueOf(aProviderTotalAmt);
                aUpdateBalList.add(tStr);
            } else {
                aBalInfoVO.totalAmt = aProviderTotalAmt;
                aBalInfoVO.balanceYM = aProviderBalYM;
                aBalInfoVO.actualBalanceDept = aProviderId;
                aBalanceList.add(aBalInfoVO);
            }
        }
    }

    /**
     * 计算相对应的供应商的订单明细结算月份
     * 
     * @param aProviderId
     *            供应商编码
     * @param aBalYM
     *            订货单位结算月份
     * @return
     * @throws GSException
     */
    private String getProviderBalanceYM(String aProviderId, String aBalYM) throws GSException {
        String tProviderBalYM = "";
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        // 查询该供应商在该月份是否有已结算的信息
        ArrayList temp2 = tBalMsgDAO.queryBalanceInfoByOrderDept(aProviderId, aBalYM, GSBaseConstants.BALANCE_STATUS);
        if (temp2.size() > 0) {
            // 该供应商在该月份已存在结算信息且状态为已结算，则将该笔数据纳入系统日期的下一个月份结算
            String curMonth = DateUtil.getCurrentDate("yyyyMM");
            int tNewMonth = Integer.parseInt(curMonth.substring(4, 6)) + 1;
            if (tNewMonth < 10) {
                tProviderBalYM = curMonth.substring(0, 4) + "0" + tNewMonth;
            } else {
                tProviderBalYM = curMonth.substring(0, 4) + tNewMonth;
            }
        } else {
            tProviderBalYM = aBalYM;
        }

        return tProviderBalYM;
    }

    /**
     * 取得结算区间
     * 
     * @param aBalYM
     *            结算月份
     * @return
     * @throws GSException
     */
    private String[] getBalDatePeriod(String aBalYM) throws GSException {
        String[] tStr = new String[2];
        try {
            GSBalanceParamDAO tBalParamDAO = new GSBalanceParamDAO();
            // 查询结算参数表
            GSBalanceParamBean tBalParamBean = tBalParamDAO.queryBalanceDate();
            String tStrDate = aBalYM;
            String tEndDate = aBalYM;
            // 判断设定的结算日期类型
            if (tBalParamBean.getGs_balance_date_type().equals(GSBaseConstants.NATURE_BALANCE_DATE)) {
                // 若为自然月则取得结算月份的第一天和最后一天作为结算区间
                Calendar tCal = Calendar.getInstance();
                tCal.set(Calendar.YEAR, Integer.parseInt(tEndDate.substring(0, 4)));
                tCal.set(Calendar.MONTH, Integer.parseInt(tEndDate.substring(4)) - 1);
                tEndDate = tEndDate + tCal.getActualMaximum(Calendar.DAY_OF_MONTH);
                tStrDate = tStrDate + "0" + 1;
            } else if (tBalParamBean.getGs_balance_date_type().equals(GSBaseConstants.MANUAL_BALANCE_DATE)) {
                // 若为手动设定的则取得设定的开始日期和结束日期作为结算区间
                if (Integer.parseInt(tBalParamBean.getGs_balance_end_date()) < 10) {
                    tEndDate = tEndDate + "0" + tBalParamBean.getGs_balance_end_date();
                } else {
                    tEndDate = tEndDate + tBalParamBean.getGs_balance_end_date();
                }
                if (Integer.parseInt(tBalParamBean.getGs_balance_start_date()) < 10) {
                    tStrDate = tStrDate + "0" + tBalParamBean.getGs_balance_start_date();
                } else {
                    tStrDate = tStrDate + tBalParamBean.getGs_balance_start_date();
                }
            }
            // 格式化日期
            tStrDate = DateUtil.formateDateTime(tStrDate);
            tEndDate = DateUtil.formateDateTime(tEndDate);
            tStr[0] = tStrDate;
            tStr[1] = tEndDate;
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException("生成结算区间异常");
        }
        return tStr;
    }

    /**
     * 按月生成所有供应商应付信息
     * 
     * @param aBalYM
     *            结算月份
     * @param aOperId
     *            操作员编号
     * @return
     * @throws GSException
     */
    public boolean productAllPayInfoByMonth(String aBalYM, String aOperId) throws GSException {
        GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
        GSPayReceiveAbleDAO tPayRecvDAO = new GSPayReceiveAbleDAO();
        GSBargainDAO tBargainDAO = new GSBargainDAO();
        // 查询费用类型序号
        GSBalanceFeeDAO tBalFeeDAO = new GSBalanceFeeDAO();
        String tFeeNo = tBalFeeDAO.getFeeTypeNo("零配件结算款（维修类）");
        boolean tFlag = false;
        Connection tConn = null;
        try {
            tConn = tBalMsgDAO.getConnetion();

            // add by Jackey start
            // 设置结算金额为0的本月数据为已结算
            try {
                tConn.setAutoCommit(false);
                tBalMsgDAO.setZeroMoneyBalanceSignYes(tConn, aBalYM);
                tConn.commit();
            } catch (Exception e) {
                if (tConn != null)
                    tConn.rollback();
            }

            // add by Jackey end

            tConn.setAutoCommit(false);
            // 判断是否所有订货单位当月都已经生成应收款
            // ArrayList tOrderDeptList =
            // tBalMsgDAO.queryOrdDeptUnBalMsgAssProvider(aBalYM,aBean.getGs_workcorp_id());

            ArrayList tOrderDeptList = tBalMsgDAO.queryOrdDeptUnBalMsg(aBalYM);
            if (tOrderDeptList.size() > 0) {
                for (int j = 0; j < tOrderDeptList.size(); j++) {
                    GSBalanceMsgBean aOrderDeptBalBean = (GSBalanceMsgBean) tOrderDeptList.get(j);
                    // 若仍有订货单位在当月未生成应收款则抛出异常
                    if (aOrderDeptBalBean.getGs_balance_sign().equals(GSBaseConstants.UNBALANCE_STATUS)) {
                        GSLogWriter.error(this, GSException.E40019_MSG);
                        throw new GSException(GSException.E40019, GSException.E40019_MSG);
                    }
                }
            } else {
                GSLogWriter.error(this, GSException.E40019_MSG);
                throw new GSException(GSException.E40019, GSException.E40019_MSG);
            }

            // 查询指定月份的所有未结算的供应商结算信息
            ArrayList tList = tBalMsgDAO.queryAllPayInfoByMonth(aBalYM);
            if (tList.size() > 0) {
                for (int i = 0; i < tList.size(); i++) {
                    GSBalanceMsgBean aBean = (GSBalanceMsgBean) tList.get(i);
                    String[] tStr = new String[5];
                    tStr[0] = GSBaseConstants.BALANCE_STATUS;
                    tStr[1] = aOperId;
                    tStr[2] = aBean.getGs_workcorp_id();
                    tStr[3] = aBalYM;
                    tStr[4] = aBean.getGs_actual_workcorp_id();
                    // 修改结算标志为已结算
                    tFlag = tBalMsgDAO.updateBalanceStatus(tConn, tStr);
                    if (!tFlag) {
                        GSLogWriter.error(this, GSException.E40018_MSG);
                        throw new GSException(GSException.E40018, GSException.E40018_MSG);
                    } else {
                        GSPayReceiveAbleBean tPayRecvAbleBean = new GSPayReceiveAbleBean();
                        tPayRecvAbleBean.setGs_workcorp_id(aBean.getGs_workcorp_id());
                        tPayRecvAbleBean.setGs_workcorp_category(aBean.getGs_workcorp_category());
                        tPayRecvAbleBean.setGs_balance_month(aBean.getGs_balance_month());
                        tPayRecvAbleBean.setGs_fee_type_id(tFeeNo);
                        // 取得收付款周期并结算应付日期
                        String tWeek = tBargainDAO.queryMaxBgnWeek(aBean.getGs_workcorp_id(), GSBaseConstants.BALANCE_PROVIDER_TYPE);
                        if (tWeek.equals("")) {
                            tWeek = "60";
                        }
                        String tPayDate = DateUtil.getNextUpDay(Integer.parseInt(tWeek));
                        tPayRecvAbleBean.setGs_pay_date(DateUtil.formateDateTime(tPayDate));

                        tPayRecvAbleBean.setGs_pay_type(aBean.getGs_pay_type());
                        tPayRecvAbleBean.setGs_balance_need(aBean.getGs_balance_sum());
                        tPayRecvAbleBean.setGs_balance_undone(aBean.getGs_balance_sum());
                        tPayRecvAbleBean.setGs_pay_status(GSBaseConstants.UNPAY);
                        tPayRecvAbleBean.setGs_principal(aBean.getGs_workcorp_id());
                        tPayRecvAbleBean.setGs_operator_id(aBean.getGs_operator_id());
                        String tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
                        tPayRecvAbleBean.setGs_operator_date(tCurDT);
                        tPayRecvAbleBean.setGs_offset_date(tCurDT);
                        tPayRecvAbleBean.setGs_receiveable_id(GenRandNum.genDTRandNum());
                        // 新增应收应付表
                        tFlag = tPayRecvDAO.insertPayReceiveInfo(tPayRecvAbleBean, tConn);
                        if (!tFlag) {
                            GSLogWriter.error(this, GSException.E40017_MSG);
                            throw new GSException(GSException.E40017, GSException.E40017_MSG);
                        }
                    }
                }
                if (tFlag) {
                    tConn.commit();
                    GSLogWriter.info(this, "应付操作成功完成");
                }
            } else {
                GSLogWriter.info(this, GSException.E40016_MSG);
                throw new GSException(GSException.E40016, GSException.E40016_MSG);
            }
        } catch (GSException ge) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            throw ge;
        } catch (Exception e) {
            if (tConn != null) {
                try {
                    tConn.rollback();
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
            GSLogWriter.error(this, e.toString());
            throw new GSException(e.toString());
        } finally {
            if (tConn != null) {
                try {
                    tConn.setAutoCommit(true);
                    GSBaseDAO.close(tConn);
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
        }
        return tFlag;
    }
    /*
     * public boolean productAllPayInfoByMonth(String aBalYM,String aOperId)
     * throws GSException{ GSBalanceMsgDAO tBalMsgDAO = new GSBalanceMsgDAO();
     * GSPayReceiveAbleDAO tPayRecvDAO = new GSPayReceiveAbleDAO(); GSBargainDAO
     * tBargainDAO = new GSBargainDAO(); //查询费用类型序号 GSBalanceFeeDAO tBalFeeDAO =
     * new GSBalanceFeeDAO(); String tFeeNo =
     * tBalFeeDAO.getFeeTypeNo("零配件结算款（维修类）"); boolean tFlag = false; Connection
     * tConn = null; try{ tConn = tBalMsgDAO.getConnetion();
     * tConn.setAutoCommit(false); //查询指定月份的所有未结算的供应商结算信息 ArrayList tList =
     * tBalMsgDAO.queryAllPayInfoByMonth(aBalYM); if(tList.size() > 0){ for(int
     * i=0; i<tList.size(); i++){ GSBalanceMsgBean aBean =
     * (GSBalanceMsgBean)tList.get(i); //查询供应商所对应订单明细的订货单位在当月的结算信息 ArrayList
     * tOrderDeptList =
     * tBalMsgDAO.queryOrdDeptUnBalMsgAssProvider(aBalYM,aBean.getGs_workcorp_id());
     * if(tOrderDeptList.size() > 0){ for(int j=0; j<tOrderDeptList.size();j++){
     * GSBalanceMsgBean aOrderDeptBalBean =
     * (GSBalanceMsgBean)tOrderDeptList.get(j); //若仍有订货单位在当月未生成应收款则抛出异常
     * if(aOrderDeptBalBean.getGs_balance_sign().equals(GSBaseConstants.UNBALANCE_STATUS)){
     * GSLogWriter.error(this,GSException.E40019_MSG); throw new
     * GSException(GSException.E40019,GSException.E40019_MSG); } } }else{
     * GSLogWriter.error(this,GSException.E40019_MSG); throw new
     * GSException(GSException.E40019,GSException.E40019_MSG); } String[] tStr =
     * new String[5]; tStr[0] = GSBaseConstants.BALANCE_STATUS; tStr[1] =
     * aOperId; tStr[2] = aBean.getGs_workcorp_id(); tStr[3] = aBalYM; tStr[4] =
     * aBean.getGs_actual_workcorp_id(); //修改结算标志为已结算 tFlag =
     * tBalMsgDAO.updateBalanceStatus(tConn,tStr); if(!tFlag){
     * GSLogWriter.error(this,GSException.E40018_MSG); throw new
     * GSException(GSException.E40018,GSException.E40018_MSG); }else{
     * GSPayReceiveAbleBean tPayRecvAbleBean = new GSPayReceiveAbleBean();
     * tPayRecvAbleBean.setGs_workcorp_id(aBean.getGs_workcorp_id());
     * tPayRecvAbleBean.setGs_workcorp_category(aBean.getGs_workcorp_category());
     * tPayRecvAbleBean.setGs_balance_month(aBean.getGs_balance_month());
     * tPayRecvAbleBean.setGs_fee_type_id(tFeeNo); //取得收付款周期并结算应付日期 String tWeek =
     * tBargainDAO.queryMaxBgnWeek(aBean.getGs_workcorp_id(),GSBaseConstants.BALANCE_PROVIDER_TYPE);
     * if(tWeek.equals("")){ tWeek = "60"; } String tPayDate =
     * DateUtil.getNextUpDay(Integer.parseInt(tWeek));
     * tPayRecvAbleBean.setGs_pay_date(DateUtil.formateDateTime(tPayDate));
     * 
     * tPayRecvAbleBean.setGs_pay_type(aBean.getGs_pay_type());
     * tPayRecvAbleBean.setGs_balance_need(aBean.getGs_balance_sum());
     * tPayRecvAbleBean.setGs_balance_undone(aBean.getGs_balance_sum());
     * tPayRecvAbleBean.setGs_pay_status(GSBaseConstants.UNPAY);
     * tPayRecvAbleBean.setGs_principal(aBean.getGs_workcorp_id());
     * tPayRecvAbleBean.setGs_operator_id(aBean.getGs_operator_id()); String
     * tCurDT = DateUtil.getCurrentDate("yyyy-MM-dd hh:mm:ss");
     * tPayRecvAbleBean.setGs_operator_date(tCurDT);
     * tPayRecvAbleBean.setGs_offset_date(tCurDT);
     * tPayRecvAbleBean.setGs_receiveable_id(GenRandNum.genDTRandNum());
     * //新增应收应付表 tFlag =
     * tPayRecvDAO.insertPayReceiveInfo(tPayRecvAbleBean,tConn); if(!tFlag){
     * GSLogWriter.error(this,GSException.E40017_MSG); throw new
     * GSException(GSException.E40017,GSException.E40017_MSG); } } } if(tFlag){
     * tConn.commit(); GSLogWriter.info(this,"应付操作成功完成"); } }else{
     * GSLogWriter.info(this,GSException.E40016_MSG); throw new
     * GSException(GSException.E40016,GSException.E40016_MSG); }
     * }catch(GSException ge){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se ){ se.printStackTrace(); } } throw ge;
     * }catch(Exception e){ if(tConn != null){ try{ tConn.rollback();
     * }catch(SQLException se ){ se.printStackTrace(); } }
     * GSLogWriter.error(this,e.toString()); throw new
     * GSException(e.toString()); }finally{ if(tConn != null){ try{
     * tConn.setAutoCommit(true); tConn.close(); }catch(SQLException se){
     * se.printStackTrace(); } } } return tFlag; }
     */
}
